Last active
August 6, 2019 15:50
-
-
Save bdaniel7/ee07f1278500febc160fec7263f0477a to your computer and use it in GitHub Desktop.
Multiple registrations of INotificationHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MeasureEmailNotification : INotification | |
{ | |
public int Id { set; get; } | |
} | |
public class MeasureEmailNotificationHandler : INotificationHandler<MeasureEmailNotification> | |
{ | |
public async Task Handle(MeasureEmailNotification emailNotification, CancellationToken cancellationToken) | |
{ | |
// just to compile | |
await Console.Out.WriteLineAsync(emailNotification.Id); | |
} | |
} | |
public class RegulationEmailNotification : INotification | |
{ | |
public int Id { set; get; } | |
} | |
public class RegulationEmailNotificationHandler : INotificationHandler<RegulationEmailNotification> | |
{ | |
public async Task Handle(RegulationEmailNotification emailNotification, CancellationToken cancellationToken) | |
{ | |
// just to compile | |
await Console.Out.WriteLineAsync(emailNotification.Id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
// domainAssembly contains all IRequest<>, IRequestHandler<>, INotification, INotificationHandler<> implementations | |
var domainAssembly = typeof(RegulationEmailNotificationHandler).Assembly; | |
services.AddMediatR(domainAssembly); | |
// ContainerBuilder is from Autofac | |
var builder = new ContainerBuilder(); | |
builder.RegisterAssemblyTypes(domainAssembly) | |
.AsImplementedInterfaces() | |
.InstancePerLifetimeScope(); | |
builder.Populate(services); | |
Container = builder.Build(); | |
return new AutofacServiceProvider(Container); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment