Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

CommandPipeline

Build status

Pipeline Pattern is helpful in dividing the problem into smaller reusable code components. This is a simple yet powerful structural pattern to organize a complex logic into smaller reusable components, which can be added/removed/modified independently.

Forces for the Pattern

  • The logic is complex.
  • The simplicity and readability of the code is critical.
  • The logic can be divided into multiple modules.
  • The modules are potentially reusable for different usecases.

Installation

CommandPipeline

Common solution for pipeline processing

You can install CommandPipeline via NuGet:

Install-Package CommandPipeline

CommandPipeline.Ninject

Install it if you want to use Ninject as dependencies resolver for commands

You can install CommandPipeline.Ninject via NuGet:

Install-Package CommandPipeline.Ninject

Example

The complete ready-to-use example is available in the CommandPipeline.Example project

Usage

Create command

publicclassExtractHtmlFromUrl:NonParameterizedCommand{publicOutArgument<HtmlDocument>HtmlPage{get;set;}publicInArgument<Request>Request{get;set;}publicIWebPageDownloaderDownloader{get;privateset;}publicExtractHtmlFromUrl(IWebPageDownloaderdownloader){this.Downloader=downloader;}publicoverridevoidExecute(){varrequest=Ensure.That(this.Request,"Request").Is(p =>p.IsNotNull());varwebPage=this.Downloader.DownloadWebPage(request.Url);varhtmlPage=newHtmlDocument{Content=webPage};this.HtmlPage.Set(htmlPage);}}

Create container

varcontainer=newNinjectContainer();container.Bind<IWebPageDownloader>().To<WebPageDownloader>();container.Bind<IMarkdownConveter>().To<MarkdownConveter>();container.Bind<IDataContainerService>().To<DataContainerServiceFake>();

Create and update context with your data (optional)

varcontext=newParametersContext<ICommand>();context.Set<ExtractHtmlFromUrl,Request>(x =>x.Request,newRequest{Url=link});

Create pipeline

builder=newPipelineBuilder()
var pipeline = builder.Create(container,context).Register<ExtractHtmlFromUrl>().Register<ConvertHtmlToMardown>().Register<UploadToDataContainer>();

Handle it

pipeline.Handle();

About

Pipeline Pattern is helpful in dividing the problem into smaller reusable code components. This is a simple yet powerful structural pattern to organize a complex logic into smaller reusable components, which can be added/removed/modified independently.

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages