我正在尝试将此代码从DI autofac重写为Ninject 3.0.0.15。
我遇到方法问题:AsImplementedInterfaces(...)和AsClosedTypesOf(...)
builder.RegisterAssemblyTypes(typeof(CategoryRepository).Assembly)
.Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces()
.InstancePerHttpRequest();
Assembly services = Assembly.Load("EFMVC.Domain");
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(ICommandHandler<>)).InstancePerHttpRequest();
builder.RegisterAssemblyTypes(services);
该代码是非常好的演示Web应用程序的一部分,用于演示ASP.NET MVC 4和EF 4.3 Code First,Windows Azure和架构实践:EFMVC
感谢您的回答!
答案 0 :(得分:3)
使用Ninject.Extensions.Conventions V3.0.0
我认为这就是你要找的东西:
kernel.Bind(x => x
.FromAssemblyContaining<CategoryRepository>()
.SelectAllClasses().EndingWith("Repository")
.BindAllInterfaces()
.Configure(b => b.InRequestScope());
kernel.Bind(x => x
.From("EFMVC.Domain")
.SelectAllClasses().InheritedFromAny(typeof(ICommandHandler<>))
.BindAllInterfaces()
.Configure(b => b.InRequestScope());