ZeroCoffe.Handlers 2.0.0

dotnet add package ZeroCoffe.Handlers --version 2.0.0                
NuGet\Install-Package ZeroCoffe.Handlers -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZeroCoffe.Handlers" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZeroCoffe.Handlers --version 2.0.0                
#r "nuget: ZeroCoffe.Handlers, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ZeroCoffe.Handlers as a Cake Addin
#addin nuget:?package=ZeroCoffe.Handlers&version=2.0.0

// Install ZeroCoffe.Handlers as a Cake Tool
#tool nuget:?package=ZeroCoffe.Handlers&version=2.0.0                

ZeroCoffe Simple Mediator Pattern

How to use version 2.0.0 Preview ZeroCoffe

You can check a full example at : https://github.com/G3ecko/ZeroCoffe/tree/master/ZeroCoffe.ExampleApi

Version 2.0.0 - Preview001
  • Change request pipline to improve performance
  • Parallel Pipeline
  • Create more response extension to help parse result from handlers
  • Create exentsions to add mediator services
  • BaseResponse has add to better output
Add sequencial or parallel pipeline
Add sequencial pipeline
services.UseZeroCoffeMediator();

OR

Add parallel pipeline
services.UseZeroCoffeMediatorParallel();

Response Extensions
TResponse GetResponse<TResponse>(this IList<IResponse> responses)
TResponse GetPreResponse<TResponse>(this IList<IResponse> responses)
bool ResponseHasErros(this IList<IResponse> responses)
TResponse GetErrorResponse<TResponse>(this IList<IResponse> responses)
List<TResponse> GetResponses<TResponse>(this IList<IResponse> responses)
List<TResponse> GetPreResponses<TResponse>(this IList<IResponse> responses)

How to use version 1.2.0
Add meditor service



public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddSingleton<IMediator, Mediator>();
    services.AddSingleton<IRequestPipeline, RequestPipeline>();
    services.AddSingleton<IHandlersServiceProvider, HandlersServiceProvider>();
}
Add Handler Service
app.RegisterService<WeatherHandlerRequest, WeatherHandler>();
app.RegisterService<ExampleRequest, ValidationExample>();
app.RegisterService<ExampleRequest, HandleExample>();
Add mediator in controller
public class WeatherForecastController : ControllerBase
{


    private readonly ILogger<WeatherForecastController> _logger;
    private readonly IMediator mediator;

    public WeatherForecastController(IMediator mediator, ILogger<WeatherForecastController> logger)
    {
        _logger = logger;
        this.mediator = mediator;
    }

    [HttpGet]
    public async Task<IActionResult> Get()
    {
        var res = await mediator.HandleRequest(new WeatherHandlerRequest());
        if (res.Any(o => o.AnyError))
        {
            return BadRequest();
        }
        else
        {
            return Ok(res.GetResponse<WeatherHandlerResponse>()?.weatherForecasts);
        }

    }

    [HttpGet]
    public async Task<IActionResult> GetWithValidator(string text)
    {
        var request = new ExampleRequest();
        request.text = text;

        var res = await mediator.HandleRequest(request);
        if (res.Any(o => o.AnyError))
        {
            return BadRequest(res);
        }
        else
        {
            return Ok(res.GetResponse<ExampleResponse>());
        }

    }
}

Add new handler and validation handler
public class ValidationExample : PreHandler<ExampleRequest, ExampleResponse>
{

    public override Task<ExampleResponse> Handle(ExampleRequest response, Dictionary<string, object> Context)
    {
        ExampleResponse exampleResponse = new ExampleResponse();
        exampleResponse.AnyError = (response == null || string.IsNullOrEmpty(response.text));
        return Task.FromResult(exampleResponse);
    }
}

public class HandleExample : Handler<ExampleRequest, ExampleResponse>
{

    public override Task<ExampleResponse> Handle(ExampleRequest response, Dictionary<string, object> Context)
    {
        ExampleResponse exampleResponse = new ExampleResponse();
        exampleResponse.textOutput = response.text;
        return Task.FromResult(exampleResponse);
    }
}
Add new handler response and request
public class ExampleResponse : IResponse
{
    public ExampleResponse()
    {

    }

    public ExampleResponse(bool anyError)
    {
        AnyError = anyError;

    }

    public bool AnyError { get; set; }
    public string textOutput { get; set; }
}

public class ExampleRequest: IRequest
{
    public string text { get; set; }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 535 5/7/2020
2.0.0-preview001 306 5/5/2020
1.2.0 547 5/4/2020 1.2.0 is deprecated.
1.1.0 575 4/30/2020 1.1.0 is deprecated.
1.0.0 535 4/28/2020 1.0.0 is deprecated.