Nancy DependencyResolver
本文关键字:DependencyResolver Nancy | 更新日期: 2023-09-27 18:18:25
我使用Nancy Framework和autoface,我在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>>();
处理程序为空!如何解决这个问题?帮帮我,谢谢。。。
我相信你正在注册类型AsSelf(这是默认的autofacc行为)。你能试试这个吗?
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(ICommandHandler<>))
.AsImplementedInterface()
.InstancePerRequest();