Skip to main content

DeeDee by joh-pot

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: DeeDee

Mediator pattern using source generation for .NET

Author: joh-pot

NuGet: https://www.nuget.org/packages/DeeDee/

You can find more details at https://github.com/joh-pot/DeeDee/

Source : https://github.com/joh-pot/DeeDee/

Original Readme

note

DeeDee

Mediator using source generation for .NET

Send in-process commands/queries to handlers either sync or async. The mechanism for sending is generated during compile time as overloads based on your code.

Installation

Nuget Package manager>Install-Package DeeDee

See wiki for full details

About

note

Mediatr generated data

How to use

Example ( source csproj, source files )

This is the CSharp Project that references DeeDee

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DeeDee" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />

</ItemGroup>

</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

using System;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using DeeDee.Models;
using ServiceProvider = DeeDee.Models.ServiceProvider;

namespace DeeDeeDemo.DeeDee.Generated.Models
{
public class Dispatcher : IDispatcher
{
private readonly ServiceProvider _serviceFactory;
private readonly Lazy<Next<Pong>> _Ping_Pong_lazy;
public Dispatcher(ServiceProvider service)
{
_serviceFactory = service;
_Ping_Pong_lazy = new Lazy<Next<Pong>>(Build<Ping, Pong>);
}

public Pong Send(Ping request)
{
var context = new PipelineContext<Pong>();
Next<Pong> builtPipeline = _Ping_Pong_lazy.Value;
return builtPipeline(request, ref context);
}

private NextAsync BuildAsync<TRequest>()
where TRequest : IRequest
{
{
var actions = _serviceFactory.GetServices<IPipelineActionAsync<TRequest>>();
var builtPipeline = actions.Aggregate((NextAsync)((req, ctx, tkn) => Task.CompletedTask), (next, pipeline) => (req, ctx, tkn) => pipeline.InvokeAsync((TRequest)req, ctx, next, tkn));
return builtPipeline;
}
}

private Next Build<TRequest>()
where TRequest : IRequest
{
{
var actions = _serviceFactory.GetServices<IPipelineAction<TRequest>>();
var builtPipeline = actions.Aggregate((Next)((IRequest req, ref PipelineContext ctx) =>
{
{
}
}), (next, pipeline) => (IRequest req, ref PipelineContext ctx) => pipeline.Invoke((TRequest)req, ref ctx, next));
return builtPipeline;
}
}

private NextAsync<TResponse> BuildAsync<TRequest, TResponse>()
where TRequest : IRequest<TResponse>
{
{
var actions = _serviceFactory.GetServices<IPipelineActionAsync<TRequest, TResponse>>();
var builtPipeline = actions.Aggregate((NextAsync<TResponse>)((req, ctx, tkn) => Task.FromResult(ctx.Result)), (next, pipeline) => (req, ctx, tkn) => pipeline.InvokeAsync((TRequest)req, ctx, next, tkn));
return builtPipeline;
}
}

private Next<TResponse> Build<TRequest, TResponse>()
where TRequest : IRequest<TResponse>
{
{
var actions = _serviceFactory.GetServices<IPipelineAction<TRequest, TResponse>>();
var builtPipeline = actions.Aggregate((Next<TResponse>)((IRequest<TResponse> req, ref PipelineContext<TResponse> ctx) => ctx.Result), (next, pipeline) => (IRequest<TResponse> req, ref PipelineContext<TResponse> ctx) => pipeline.Invoke((TRequest)req, ref ctx, next));
return builtPipeline;
}
}
}
}

Usefull

Download Example (.NET C# )

Share DeeDee

https://ignatandrei.github.io/RSCG_Examples/v2/docs/DeeDee

In the same category (Mediator) - 2 other generators

Immediate.Handlers

Mediator