I'm using ASP.NET Core, with the built-in container. Automatic registration is done like so:
services.AddMvc();
services.AddMediatR(typeof(Startup));
This automatically 1) configures MediatR, and 2) registers all handlers found in the assembly.
But how do I register my handlers manually?
I saw this in the source:
public static void AddMediatR(this IServiceCollection services, IEnumerable<Type> handlerAssemblyMarkerTypes)
{
AddRequiredServices(services);
AddMediatRClasses(services, handlerAssemblyMarkerTypes.Select(t => t.GetTypeInfo().Assembly));
}
I assume I should call AddRequiredServices() to setup MediatR itself, and then manually register my handlers using services.AddTransient<MyHandler>().
But AddRequiredServices() is private.
Register handlers manually?
Don't use this package? The point of this package is to automatically register handlers.
@jbogard My point is if I manually register handlers, surely there is more I need to do to configure MediatR itself?
The AddMediatR() automatic registration calls
AddRequiredServices(services);
AddMediatRClasses(services, handlerAssemblyMarkerTypes.Select(t => t.GetTypeInfo().Assembly));
The second is to register handlers, which I'd like to do manually.
But the first first is for MediatR itself. Which is private. I assume I need to implement that?
Oh yeah, at that point I'd just look at the code inside this and copy-paste what you need for your project.
Yeah. Would be useful if that method were public though.
Most helpful comment
Yeah. Would be useful if that method were public though.