我正在使用Nancy Framework和autofac,我在Bootstrapper中确实喜欢这个:
var services = Assembly.Load("ProjectDomain");
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(ICommandHandler<>))
.InstancePerRequest();
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(IValidationHandler<>))
.InstancePerRequest();
但它不起作用.....
ICommandHandler<TCommand> handler =
DependencyResolver.Current.GetService<ICommandHandler<TCommand>>();
处理程序为空!如何解决?帮助我,谢谢...
答案 0 :(得分:0)
我相信你正在注册类型AsSelf(这是默认的autofac行为)。你能试试吗?
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(ICommandHandler<>))
.AsImplementedInterface()
.InstancePerRequest();