Skip to content

Furlong provides several implementations of the Chain of Responsibility pattern, supporting sync, async-await, request, request-response, and local delegates.

License

Notifications You must be signed in to change notification settings

dungeym/Furlong

Repository files navigation

Furlong

Furlong provides several implementations of the Chain of Responsibility pattern, supporting sync, async-await, request, request-response, and local delegates (also using async-await, et al).

build code coverage codacy NuGet Badge

Introduction

This netstandard2.0 library contains several implementations of the Chain of Responsibility pattern, one of the Behavioural Patterns from the Gang of Four.

Each implementation has the following characteristics.

  • A chain represents two or more links.
  • A chain can only be accessed by the first link.
  • Each link determines if the request should be passed to the next link in the chain.

Installation

Install the library from NuGet using:

dotnet add package Furlong

Basic Examples

Simple chain with no response.

var chain = ChainFactory<MyRequest>
		.Initialize()
		.StartWith(new MyLink1())
		.FollowedBy(new MyLink2())
		.FollowedBy(new MyLink3())
		.Build();

var request = new MyRequest();

chain.Handle(request);

Asynchronous chain returning a response.

var chain = AsyncChainFactory<MyRequest>
		.Initialize()
		.StartWith(new MyLink1())
		.FollowedBy(new MyLink2())
		.FollowedBy(new MyLink3())
		.Build();

var request = new MyRequest();

var source = new CancellationTokenSource();

var response = await chain.HandleAsync(request, source.Token);

Synchronous chain using local delegates, with no response.

var chain = LocalChainFactory<MyRequest>
		.Initialize()
		.StartWith(Handle1)
		.FollowedBy(Handle2)
		.FollowedBy(Handle3)
		.Build();

var request = new MyRequest();

chain.Handle(request);

private void Handle1(MyRequest request, out bool cancel)
{
	cancel = false;
	
	// Do something..
}

Further Examples

Further examples can be found in the Unit Tests project, these include:

  1. Simple Dependency Injection
  2. Dependency Injection using a Context Resolver
  3. Using a custom interface as the request definition

Feedback

Please add any feedback or issue to the Issues section in this project.

License

This project is licensed under the MIT license.

Copyright and Trademarks

This library is copyright (©) Mark Dungey 2000-2020.

About

Furlong provides several implementations of the Chain of Responsibility pattern, supporting sync, async-await, request, request-response, and local delegates.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages