alsami / MediatR.Extensions.Autofac.DependencyInjection

Autofac plug-in for MediatR.
MIT License
55 stars 14 forks source link

Handlers Manually Option #10

Closed fdhsdrdark closed 2 years ago

fdhsdrdark commented 2 years ago

Not a issue, just a question please: Is there a way to register Handlers manually?

That is, on start up - based on configuration register the required Handlers. This will allow to have multiple handlers implementation for the same command and decide witch implementation will be used.

Thank you very much for any response.

alsami commented 2 years ago

Currently that is not possible. I've started building something that would allow configuration but haven't had the chance to finish it.

I will try to get this done in the next days.

Just out of curiousity: why two different command-handlers for same command? Does it relate to multi-tenancy?

alsami commented 2 years ago

Version 8.2.0 will be released shortly.

You can basically now do the following:

var configuration = MediatRConfigurationBuilder
    .Create(typeof(ResponseCommand).Assembly)
    // this will register all mediatr open-generic types
    // except of types derived from IRequestHandler<TRequest, TResponse>
    .WithRequestHandlersManuallyRegistered()
    .Build();

var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterMediatR(configuration);
containerBuilder.RegisterType<MyHandlerType>().As<IRequestHandler<MyCommand, MyResponse>>();
var container = containerBuilder.Build();
// and so on