-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathMediatorModule.cs
More file actions
41 lines (36 loc) · 1.98 KB
/
MediatorModule.cs
File metadata and controls
41 lines (36 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Autofac;
using Duber.Invoice.API.Application.DomainEventHandlers;
using MediatR;
using System.Collections.Generic;
using System.Reflection;
namespace Duber.Invoice.API.Infrastructure.AutofacModules
{
public class MediatorModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
Autofac.Builder.IRegistrationBuilder<Mediator, Autofac.Builder.ConcreteReflectionActivatorData, Autofac.Builder.SingleRegistrationStyle> registrationBuilder2 = builder.RegisterType<Mediator>().As<IMediator>();
// Register all the event classes (they implement INotificationHandler) in assembly holding the Commands
builder.RegisterAssemblyTypes(typeof(InvoiceCreatedDomainEventHandler).GetTypeInfo().Assembly)
.AsClosedTypesOf(typeof(INotificationHandler<>)).AsImplementedInterfaces().InstancePerRequest();
Autofac.Builder.IRegistrationBuilder<ServiceFactory, Autofac.Builder.SimpleActivatorData, Autofac.Builder.SingleRegistrationStyle> registrationBuilder1 = builder.Register<ServiceFactory>(context =>
{
IComponentContext componentContext = context.Resolve<IComponentContext>();
return t =>
{
ServiceFactory p = t => { return componentContext.TryResolve(t, out object o) ? o : null; };
return t;
};
});
Autofac.Builder.IRegistrationBuilder<ServiceFactory, Autofac.Builder.SimpleActivatorData, Autofac.Builder.SingleRegistrationStyle> registrationBuilder = builder.Register<ServiceFactory>(context =>
{
IComponentContext componentContext = context.Resolve<IComponentContext>();
return t =>
{
IEnumerable<object> resolved = (IEnumerable<object>)componentContext.Resolve(typeof(IEnumerable<>).MakeGenericType(t));
return resolved;
};
});
}
}
}