using System.Threading.Tasks;
public static void Main()
c.RegisterMany(new[] { typeof(IMediator).GetAssembly(), typeof(SomeRequestHandler).GetAssembly() }, type => type.GetTypeInfo().IsInterface);
c.RegisterDelegate<SingleInstanceFactory>(r => serviceType => r.Resolve(serviceType));
c.RegisterDelegate<MultiInstanceFactory>(r => serviceType => r.ResolveMany(serviceType));
c.Register<DbContext, Model1>(reuse: Reuse.InResolutionScopeOf(typeof(IAsyncRequestHandler<,>)));
c.Register<DbContext, Model1>(reuse: Reuse.InResolutionScopeOf(typeof(IAsyncNotificationHandler<>)));
var mediator = c.Resolve<IMediator>();
mediator.SendAsync(new RequestCommand()).Wait();
public interface IActionHandler
DbContext DbContext { get; }
public class Model1 : DbContext {}
public class RequestCommand : IAsyncRequest<string>
public class Notification : IAsyncNotification
public class SomeRequestHandler : IAsyncRequestHandler<RequestCommand, string>
public DbContext DbContext { get; private set; }
public IMediator Mediator { get; private set; }
public SomeRequestHandler(DbContext dbContext, IMediator mediator)
public Task<string> Handle(RequestCommand message)
Console.WriteLine("request called");
Mediator.PublishAsync(new Notification()).Wait();
return Task.FromResult("ret");
public class SomeNotificationHandler : IAsyncNotificationHandler<Notification>
public DbContext DbContext { get; private set; }
public SomeNotificationHandler(DbContext dbContext)
public Task Handle(Notification notification)
Console.WriteLine("notification called");
return Task.FromResult(0);