Skip to content

Instantly share code, notes, and snippets.

View DanielGilbert's full-sized avatar
🏠
Working from home

Daniel Gilbert DanielGilbert

🏠
Working from home
View GitHub Profile
@DanielGilbert
DanielGilbert / MediatRExtensions.cs
Created February 19, 2017 00:02 — forked from rmacfie/MediatRExtensions.cs
Register MediatR handlers in Asp.Net 5 / vNext / Core
namespace Microsoft.AspNet.Builder
{
public static class MediatRExtensions
{
public static IServiceCollection AddMediatR(this IServiceCollection services, params Assembly[] handlerAssemblies)
{
services.AddTransient<IMediator>(x => new Mediator(x.GetService<SingleInstanceFactory>(), x.GetService<MultiInstanceFactory>()));
services.AddTransient<SingleInstanceFactory>(x => t => x.GetRequiredService(t));
services.AddTransient<MultiInstanceFactory>(x => t => x.GetServices(t));