I'm using Nancy Framework and autofac, i did like this in Bootstrapper :
var services = Assembly.Load("ProjectDomain");
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(ICommandHandler<>))
.InstancePerRequest();
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(IValidationHandler<>))
.InstancePerRequest();
but it doesn't work.....
ICommandHandler<TCommand> handler =
DependencyResolver.Current.GetService<ICommandHandler<TCommand>>();
handler is null! how to fix it out? help me, thanks。。。
I believe you're registering the types AsSelf (which is the default autofac behavior). Could you try this?
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(ICommandHandler<>))
.AsImplementedInterface()
.InstancePerRequest();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.