Closed ivanpaulovich closed 4 years ago
Another good sample is available here https://github.com/ivanpaulovich/clean-architecture-manga
Hi @ivanpaulovich, I'm using the Fluent Mediator on a new project I'm working on.
The AddFluentMediator is getting bigger so I want to split the building of it into methods. Today it's like
`services.AddFluentMediator(
builder =>
{
builder.On
builder.On<Application.Companies.Establishments.CreateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.CreateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.UpdateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.UpdateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.DeleteEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.DeleteEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.GetEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.GetEstablishment.IUseCase>((handler, request) => handler.Request(request));
});`
I want something like that:
`public static IServiceCollection AddMediator(this IServiceCollection services) { AddOrganizationalGroupsMediator(services);
AddEstablishmentsMediator(services);
return services;
}
private static void AddOrganizationalGroupsMediator(IServiceCollection services)
{
services.AddFluentMediator(
builder =>
{
builder.On<Application.Companies.OrganizationalGroups.CreateOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.CreateOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.UpdateOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.UpdateOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.DeleteOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.DeleteOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.GetOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.GetOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
});
}
private static void AddEstablishmentsMediator(IServiceCollection services)
{
services.AddFluentMediator(
builder =>
{
builder.On<Application.Companies.Establishments.CreateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.CreateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.UpdateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.UpdateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.DeleteEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.DeleteEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.GetEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.GetEstablishment.IUseCase>((handler, request) => handler.Request(request));
});
}`
But it's not possible today. Is am I doing it wrong? Or there is no support for it yet?
Hey @leandrofagundes,
Sorry for the late response, I am getting back to the computer today after good weeks of vacation and celebrations 🍺
My suggestion to achieve this fine grained setup is to use IPipelineProviderBuilder
as an argument on each of your methods.
These methods:
private static void AddEstablishmentsMediator(IServiceCollection services)
{
services.AddFluentMediator(
builder =>
{
builder.On<Application.Companies.Establishments.CreateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.CreateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.UpdateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.UpdateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.DeleteEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.DeleteEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.GetEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.GetEstablishment.IUseCase>((handler, request) => handler.Request(request));
});
}
private static void AddOrganizationalGroupsMediator(IServiceCollection services)
{
services.AddFluentMediator(
builder =>
{
builder.On<Application.Companies.OrganizationalGroups.CreateOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.CreateOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.UpdateOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.UpdateOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.DeleteOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.DeleteOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.GetOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.GetOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
});
}
Would be:
private static void AddEstablishmentsMediator(IPipelineProviderBuilder builder)
{
builder.On<Application.Companies.Establishments.CreateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.CreateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.UpdateEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.UpdateEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.DeleteEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.DeleteEstablishment.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.Establishments.GetEstablishment.InputData>().PipelineAsync()
.Call<Application.Companies.Establishments.GetEstablishment.IUseCase>((handler, request) => handler.Request(request));
}
private static void AddOrganizationalGroupsMediator(IPipelineProviderBuilder builder)
{
builder.On<Application.Companies.OrganizationalGroups.CreateOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.CreateOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.UpdateOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.UpdateOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.DeleteOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.DeleteOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
builder.On<Application.Companies.OrganizationalGroups.GetOrganizationalGroup.InputData>().PipelineAsync()
.Call<Application.Companies.OrganizationalGroups.GetOrganizationalGroup.IUseCase>((handler, request) => handler.Request(request));
}
public static void AddMediator(IServiceCollection services)
{
var pipelineProviderBuilder = new PipelineProviderBuilder();
AddEstablishmentsMediator(pipelineProviderBuilder);
AddOrganizationalGroupsMediator(pipelineProviderBuilder);
var pipelineProvider = pipelineProviderBuilder.Build();
services.AddTransient<GetService>(c => c.GetService);
services.AddTransient(c => pipelineProvider);
services.AddTransient<IMediator, Mediator>();
return services;
}
It should work as expected.
Great @ivanpaulovich! You always have an answer!
Sorry for being off too much too, this time of year (mainly in Brazil, you know) people stay too much time away from computers and too much time close to the beachs (bastards).
I'll keep learning with your project and help everytime I can.
Thanks
Samples projet were updated https://github.com/ivanpaulovich/FluentMediator/tree/master/samples