0
我mediatr模塊
public class MediatorModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
builder
.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(typeof(Get).GetTypeInfo().Assembly)
.As(o => o.GetInterfaces()
.Where(i => i.IsClosedTypeOf(typeof(IAsyncRequestHandler<,>)))
.Select(i => new KeyedService("Handler", i)));
builder.Register<SingleInstanceFactory>(context =>
{
var c = context.Resolve<IComponentContext>();
return t => c.Resolve(t);
});
builder.Register<MultiInstanceFactory>(context =>
{
var c = context.Resolve<IComponentContext>();`
return t => (IEnumerable<object>)c.Resolve(typeof(IEnumerable<>).MakeGenericType(t));
});
builder
.RegisterGenericDecorator(
typeof(MediatorDecorator<,>),
typeof(IAsyncRequestHandler<,>),
"Handler");
}
}
}
Autofac.Core.Registration.ComponentNotRegisteredException was unhandled by user code
HResult=-2146233088
Message=The requested service 'MediatR.IAsyncRequestHandler`2[[SCA.Prospects.Core.Application.Prospect.Crear+Command, SCA.Prospects.Core.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[MediatR.Unit, MediatR, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null]]' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
源= Autofac