diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/FilterAttribute.cs b/FilterAttribute.cs new file mode 100644 index 0000000..38a3df2 --- /dev/null +++ b/FilterAttribute.cs @@ -0,0 +1,21 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class FilterAttribute : RequestHandlerAttribute + { + private readonly Type _handlerType; + + public FilterAttribute(int step, Type handlerType, HandlerTiming timing = HandlerTiming.Before) : base(step, timing) + { + _handlerType = handlerType; + } + + public override Type GetHandlerType() + { + return _handlerType; + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/FilterAttribute.cs b/FilterAttribute.cs new file mode 100644 index 0000000..38a3df2 --- /dev/null +++ b/FilterAttribute.cs @@ -0,0 +1,21 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class FilterAttribute : RequestHandlerAttribute + { + private readonly Type _handlerType; + + public FilterAttribute(int step, Type handlerType, HandlerTiming timing = HandlerTiming.Before) : base(step, timing) + { + _handlerType = handlerType; + } + + public override Type GetHandlerType() + { + return _handlerType; + } + } +} \ No newline at end of file diff --git a/HandlerFactory.cs b/HandlerFactory.cs new file mode 100644 index 0000000..8671532 --- /dev/null +++ b/HandlerFactory.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + internal class HandlerFactory : IAmAHandlerFactory + { + private readonly ServiceProvider _serviceProvider; + + public HandlerFactory(ServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public IHandleRequests Create(Type handlerType) + { + return _serviceProvider.GetRequiredService(handlerType) as IHandleRequests; + } + + public void Release(IHandleRequests handler) { } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/FilterAttribute.cs b/FilterAttribute.cs new file mode 100644 index 0000000..38a3df2 --- /dev/null +++ b/FilterAttribute.cs @@ -0,0 +1,21 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class FilterAttribute : RequestHandlerAttribute + { + private readonly Type _handlerType; + + public FilterAttribute(int step, Type handlerType, HandlerTiming timing = HandlerTiming.Before) : base(step, timing) + { + _handlerType = handlerType; + } + + public override Type GetHandlerType() + { + return _handlerType; + } + } +} \ No newline at end of file diff --git a/HandlerFactory.cs b/HandlerFactory.cs new file mode 100644 index 0000000..8671532 --- /dev/null +++ b/HandlerFactory.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + internal class HandlerFactory : IAmAHandlerFactory + { + private readonly ServiceProvider _serviceProvider; + + public HandlerFactory(ServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public IHandleRequests Create(Type handlerType) + { + return _serviceProvider.GetRequiredService(handlerType) as IHandleRequests; + } + + public void Release(IHandleRequests handler) { } + } +} \ No newline at end of file diff --git a/Logging.cs b/Logging.cs new file mode 100644 index 0000000..6d56551 --- /dev/null +++ b/Logging.cs @@ -0,0 +1,30 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class LoggingAttribute : RequestHandlerAttribute + { + public LoggingAttribute(int step) : base(step) { } + + public override object[] InitializerParams() + { + return new object[] { Timing }; + } + + public override Type GetHandlerType() + { + return typeof(LoggingHandler<>); + } + } + + public class LoggingHandler + : RequestHandler where TRequest : class, IRequest + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Generic Logging {typeof(TRequest)}"); + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/FilterAttribute.cs b/FilterAttribute.cs new file mode 100644 index 0000000..38a3df2 --- /dev/null +++ b/FilterAttribute.cs @@ -0,0 +1,21 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class FilterAttribute : RequestHandlerAttribute + { + private readonly Type _handlerType; + + public FilterAttribute(int step, Type handlerType, HandlerTiming timing = HandlerTiming.Before) : base(step, timing) + { + _handlerType = handlerType; + } + + public override Type GetHandlerType() + { + return _handlerType; + } + } +} \ No newline at end of file diff --git a/HandlerFactory.cs b/HandlerFactory.cs new file mode 100644 index 0000000..8671532 --- /dev/null +++ b/HandlerFactory.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + internal class HandlerFactory : IAmAHandlerFactory + { + private readonly ServiceProvider _serviceProvider; + + public HandlerFactory(ServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public IHandleRequests Create(Type handlerType) + { + return _serviceProvider.GetRequiredService(handlerType) as IHandleRequests; + } + + public void Release(IHandleRequests handler) { } + } +} \ No newline at end of file diff --git a/Logging.cs b/Logging.cs new file mode 100644 index 0000000..6d56551 --- /dev/null +++ b/Logging.cs @@ -0,0 +1,30 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class LoggingAttribute : RequestHandlerAttribute + { + public LoggingAttribute(int step) : base(step) { } + + public override object[] InitializerParams() + { + return new object[] { Timing }; + } + + public override Type GetHandlerType() + { + return typeof(LoggingHandler<>); + } + } + + public class LoggingHandler + : RequestHandler where TRequest : class, IRequest + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Generic Logging {typeof(TRequest)}"); + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/PipesAndFilters.csproj b/PipesAndFilters.csproj new file mode 100644 index 0000000..91fd91f --- /dev/null +++ b/PipesAndFilters.csproj @@ -0,0 +1,14 @@ + + + + Exe + net5.0 + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/FilterAttribute.cs b/FilterAttribute.cs new file mode 100644 index 0000000..38a3df2 --- /dev/null +++ b/FilterAttribute.cs @@ -0,0 +1,21 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class FilterAttribute : RequestHandlerAttribute + { + private readonly Type _handlerType; + + public FilterAttribute(int step, Type handlerType, HandlerTiming timing = HandlerTiming.Before) : base(step, timing) + { + _handlerType = handlerType; + } + + public override Type GetHandlerType() + { + return _handlerType; + } + } +} \ No newline at end of file diff --git a/HandlerFactory.cs b/HandlerFactory.cs new file mode 100644 index 0000000..8671532 --- /dev/null +++ b/HandlerFactory.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + internal class HandlerFactory : IAmAHandlerFactory + { + private readonly ServiceProvider _serviceProvider; + + public HandlerFactory(ServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public IHandleRequests Create(Type handlerType) + { + return _serviceProvider.GetRequiredService(handlerType) as IHandleRequests; + } + + public void Release(IHandleRequests handler) { } + } +} \ No newline at end of file diff --git a/Logging.cs b/Logging.cs new file mode 100644 index 0000000..6d56551 --- /dev/null +++ b/Logging.cs @@ -0,0 +1,30 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class LoggingAttribute : RequestHandlerAttribute + { + public LoggingAttribute(int step) : base(step) { } + + public override object[] InitializerParams() + { + return new object[] { Timing }; + } + + public override Type GetHandlerType() + { + return typeof(LoggingHandler<>); + } + } + + public class LoggingHandler + : RequestHandler where TRequest : class, IRequest + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Generic Logging {typeof(TRequest)}"); + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/PipesAndFilters.csproj b/PipesAndFilters.csproj new file mode 100644 index 0000000..91fd91f --- /dev/null +++ b/PipesAndFilters.csproj @@ -0,0 +1,14 @@ + + + + Exe + net5.0 + + + + + + + + + diff --git a/PlaceOrder.cs b/PlaceOrder.cs new file mode 100644 index 0000000..b2eb61c --- /dev/null +++ b/PlaceOrder.cs @@ -0,0 +1,61 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class PlaceOrderCommand : IRequest + { + public PlaceOrderCommand(Guid id) + { + Id = id; + } + + public Guid Id { get; set; } + } + + public class PlaceOrderHandler : RequestHandler + { + [Logging(1)] + [Filter(2, typeof(RetryHandler<>))] + [Filter(3, typeof(ValidationHandler<>))] + public override PlaceOrderCommand Handle(PlaceOrderCommand command) + { + Console.WriteLine($"Placing Order: {command.Id}"); + return base.Handle(command); + } + } + + public class RetryHandler + : RequestHandler where TRequest : PlaceOrderCommand + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine("Retry Handler Executing"); + + try + { + return base.Handle(command); + } + catch (InvalidOperationException) + { + return base.Handle(command); + } + } + } + + public class ValidationHandler + : RequestHandler where TRequest : PlaceOrderCommand + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Validating {nameof(PlaceOrderCommand)}"); + + if (command.Id == Guid.Empty) + { + throw new InvalidOperationException("Invalid Order Id."); + } + + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/FilterAttribute.cs b/FilterAttribute.cs new file mode 100644 index 0000000..38a3df2 --- /dev/null +++ b/FilterAttribute.cs @@ -0,0 +1,21 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class FilterAttribute : RequestHandlerAttribute + { + private readonly Type _handlerType; + + public FilterAttribute(int step, Type handlerType, HandlerTiming timing = HandlerTiming.Before) : base(step, timing) + { + _handlerType = handlerType; + } + + public override Type GetHandlerType() + { + return _handlerType; + } + } +} \ No newline at end of file diff --git a/HandlerFactory.cs b/HandlerFactory.cs new file mode 100644 index 0000000..8671532 --- /dev/null +++ b/HandlerFactory.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + internal class HandlerFactory : IAmAHandlerFactory + { + private readonly ServiceProvider _serviceProvider; + + public HandlerFactory(ServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public IHandleRequests Create(Type handlerType) + { + return _serviceProvider.GetRequiredService(handlerType) as IHandleRequests; + } + + public void Release(IHandleRequests handler) { } + } +} \ No newline at end of file diff --git a/Logging.cs b/Logging.cs new file mode 100644 index 0000000..6d56551 --- /dev/null +++ b/Logging.cs @@ -0,0 +1,30 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class LoggingAttribute : RequestHandlerAttribute + { + public LoggingAttribute(int step) : base(step) { } + + public override object[] InitializerParams() + { + return new object[] { Timing }; + } + + public override Type GetHandlerType() + { + return typeof(LoggingHandler<>); + } + } + + public class LoggingHandler + : RequestHandler where TRequest : class, IRequest + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Generic Logging {typeof(TRequest)}"); + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/PipesAndFilters.csproj b/PipesAndFilters.csproj new file mode 100644 index 0000000..91fd91f --- /dev/null +++ b/PipesAndFilters.csproj @@ -0,0 +1,14 @@ + + + + Exe + net5.0 + + + + + + + + + diff --git a/PlaceOrder.cs b/PlaceOrder.cs new file mode 100644 index 0000000..b2eb61c --- /dev/null +++ b/PlaceOrder.cs @@ -0,0 +1,61 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class PlaceOrderCommand : IRequest + { + public PlaceOrderCommand(Guid id) + { + Id = id; + } + + public Guid Id { get; set; } + } + + public class PlaceOrderHandler : RequestHandler + { + [Logging(1)] + [Filter(2, typeof(RetryHandler<>))] + [Filter(3, typeof(ValidationHandler<>))] + public override PlaceOrderCommand Handle(PlaceOrderCommand command) + { + Console.WriteLine($"Placing Order: {command.Id}"); + return base.Handle(command); + } + } + + public class RetryHandler + : RequestHandler where TRequest : PlaceOrderCommand + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine("Retry Handler Executing"); + + try + { + return base.Handle(command); + } + catch (InvalidOperationException) + { + return base.Handle(command); + } + } + } + + public class ValidationHandler + : RequestHandler where TRequest : PlaceOrderCommand + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Validating {nameof(PlaceOrderCommand)}"); + + if (command.Id == Guid.Empty) + { + throw new InvalidOperationException("Invalid Order Id."); + } + + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..384d01f --- /dev/null +++ b/Program.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + class Program + { + static void Main(string[] args) + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddTransient(); + serviceCollection.AddTransient>(); + serviceCollection.AddTransient>(); + serviceCollection.AddTransient>(); + var serviceProvider = serviceCollection.BuildServiceProvider(); + + var registry = new SubscriberRegistry(); + registry.Register(); + + var builder = CommandProcessorBuilder.With() + .Handlers(new HandlerConfiguration( + subscriberRegistry: registry, + handlerFactory: new HandlerFactory(serviceProvider) + )) + .DefaultPolicy() + .NoTaskQueues() + .RequestContextFactory(new InMemoryRequestContextFactory()); + + var commandProcessor = builder.Build(); + commandProcessor.Send(new PlaceOrderCommand(Guid.NewGuid())); + } + } + + +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c986da --- /dev/null +++ b/.gitignore @@ -0,0 +1,258 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +**/wwwroot/lib/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml +pub/ +/src/Web/WebMVC/Properties/PublishProfiles/eShopOnContainersWebMVC2016 - Web Deploy-publish.ps1 +/src/Web/WebMVC/Properties/PublishProfiles/publish-module.psm1 +/src/Services/Identity/eShopOnContainers.Identity/Properties/launchSettings.json + +#Ignore marker-file used to know which docker files we have. +.eshopdocker_* diff --git a/FilterAttribute.cs b/FilterAttribute.cs new file mode 100644 index 0000000..38a3df2 --- /dev/null +++ b/FilterAttribute.cs @@ -0,0 +1,21 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class FilterAttribute : RequestHandlerAttribute + { + private readonly Type _handlerType; + + public FilterAttribute(int step, Type handlerType, HandlerTiming timing = HandlerTiming.Before) : base(step, timing) + { + _handlerType = handlerType; + } + + public override Type GetHandlerType() + { + return _handlerType; + } + } +} \ No newline at end of file diff --git a/HandlerFactory.cs b/HandlerFactory.cs new file mode 100644 index 0000000..8671532 --- /dev/null +++ b/HandlerFactory.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + internal class HandlerFactory : IAmAHandlerFactory + { + private readonly ServiceProvider _serviceProvider; + + public HandlerFactory(ServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public IHandleRequests Create(Type handlerType) + { + return _serviceProvider.GetRequiredService(handlerType) as IHandleRequests; + } + + public void Release(IHandleRequests handler) { } + } +} \ No newline at end of file diff --git a/Logging.cs b/Logging.cs new file mode 100644 index 0000000..6d56551 --- /dev/null +++ b/Logging.cs @@ -0,0 +1,30 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class LoggingAttribute : RequestHandlerAttribute + { + public LoggingAttribute(int step) : base(step) { } + + public override object[] InitializerParams() + { + return new object[] { Timing }; + } + + public override Type GetHandlerType() + { + return typeof(LoggingHandler<>); + } + } + + public class LoggingHandler + : RequestHandler where TRequest : class, IRequest + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Generic Logging {typeof(TRequest)}"); + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/PipesAndFilters.csproj b/PipesAndFilters.csproj new file mode 100644 index 0000000..91fd91f --- /dev/null +++ b/PipesAndFilters.csproj @@ -0,0 +1,14 @@ + + + + Exe + net5.0 + + + + + + + + + diff --git a/PlaceOrder.cs b/PlaceOrder.cs new file mode 100644 index 0000000..b2eb61c --- /dev/null +++ b/PlaceOrder.cs @@ -0,0 +1,61 @@ +using System; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + public class PlaceOrderCommand : IRequest + { + public PlaceOrderCommand(Guid id) + { + Id = id; + } + + public Guid Id { get; set; } + } + + public class PlaceOrderHandler : RequestHandler + { + [Logging(1)] + [Filter(2, typeof(RetryHandler<>))] + [Filter(3, typeof(ValidationHandler<>))] + public override PlaceOrderCommand Handle(PlaceOrderCommand command) + { + Console.WriteLine($"Placing Order: {command.Id}"); + return base.Handle(command); + } + } + + public class RetryHandler + : RequestHandler where TRequest : PlaceOrderCommand + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine("Retry Handler Executing"); + + try + { + return base.Handle(command); + } + catch (InvalidOperationException) + { + return base.Handle(command); + } + } + } + + public class ValidationHandler + : RequestHandler where TRequest : PlaceOrderCommand + { + public override TRequest Handle(TRequest command) + { + Console.WriteLine($"Validating {nameof(PlaceOrderCommand)}"); + + if (command.Id == Guid.Empty) + { + throw new InvalidOperationException("Invalid Order Id."); + } + + return base.Handle(command); + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..384d01f --- /dev/null +++ b/Program.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Paramore.Brighter; + +namespace PipesAndFilters +{ + class Program + { + static void Main(string[] args) + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddTransient(); + serviceCollection.AddTransient>(); + serviceCollection.AddTransient>(); + serviceCollection.AddTransient>(); + var serviceProvider = serviceCollection.BuildServiceProvider(); + + var registry = new SubscriberRegistry(); + registry.Register(); + + var builder = CommandProcessorBuilder.With() + .Handlers(new HandlerConfiguration( + subscriberRegistry: registry, + handlerFactory: new HandlerFactory(serviceProvider) + )) + .DefaultPolicy() + .NoTaskQueues() + .RequestContextFactory(new InMemoryRequestContextFactory()); + + var commandProcessor = builder.Build(); + commandProcessor.Send(new PlaceOrderCommand(Guid.NewGuid())); + } + } + + +} diff --git a/RussianDoll.cs b/RussianDoll.cs new file mode 100644 index 0000000..3b06ad5 --- /dev/null +++ b/RussianDoll.cs @@ -0,0 +1,48 @@ +using System; + +namespace PipesAndFilters +{ + public class RussianDoll + { + public void Pump(string request) + { + Logging(request, o1 => + Validation(o1, o2 => + Retry(o2, o3 => + Receiver(o3, o4 => { })))); + } + + private void Logging(string request, Action nextFilter) + { + Console.WriteLine("Logging Request"); + nextFilter(request); + } + + private void Validation(string request, Action nextFilter) + { + if (request == "Hello World") + { + nextFilter(request); + } + } + + private void Retry(string request, Action nextFilter) + { + try + { + nextFilter(request); + } + catch (InvalidOperationException) + { + nextFilter(request); + } + } + + private void Receiver(string request, Action nextFilter) + { + Console.WriteLine($"Thanks for the request: {request}"); + + nextFilter(request); + } + } +} \ No newline at end of file