问题描述
我需要添加成员重新启动(RavenDb)到使用国际奥委会简单喷油器项目
I need add membership reboot (RavenDb) into the project that use IOC Simple Injector
Ninject实施
var config = MembershipRebootConfig.Create();
kernel.Bind<MembershipRebootConfiguration<HierarchicalUserAccount>>().ToConstant(config);
kernel.Bind<UserAccountService<HierarchicalUserAccount>>().ToSelf(); kernel.Bind<AuthenticationService<HierarchicalUserAccount().To<SamAuthenticationService<HierarchicalUserAccount>>();
kernel.Bind<IUserAccountRepository<HierarchicalUserAccount>>().ToMethod(ctx => new BrockAllen.MembershipReboot.RavenDb.RavenUserAccountRepository("RavenDb"));
kernel.Bind<IUserAccountQuery>().ToMethod(ctx => new BrockAllen.MembershipReboot.RavenDb.RavenUserAccountRepository("RavenDb"));
简单的注射器实施
Simple Injector implementation
container.Register(MembershipRebootConfig.Create);
container.Register<UserAccountService<HierarchicalUserAccount>>();
container.Register<AuthenticationService<HierarchicalUserAccount>, SamAuthenticationService<HierarchicalUserAccount>>();
container.Register<IUserAccountRepository<HierarchicalUserAccount>>(() => new RavenUserAccountRepository("RavenDb"), Lifestyle.Singleton);
container.Register<IUserAccountQuery>(() => new RavenUserAccountRepository("RavenDb"));
在行
container.Register<UserAccountService<HierarchicalUserAccount>>();
我有一个错误
对于容器能够创建UserAccountService,它应该包含一个公共构造函数,但它有2个。
参数名:TConcrete
I have an errorFor the container to be able to create UserAccountService, it should contain exactly one public constructor, but it has 2.Parameter name: TConcrete
感谢您的帮助。
推荐答案
简单的喷油器迫使你让你的组件有一个单一的公共构造方法,因为其的。
Simple Injector forces you to let your components to have one single public constructor, because having multiple injection constructors is an anti-pattern.
在情况下, UserAccountService
是code库的一部分,你应该删除不应该被用于自动布线构造。
In case the UserAccountService
is part of your code base, you should remove the constructor that should not be used for auto-wiring.
在情况下, UserAccountService
是一个可重用库的一部分,你应该说明的。在这种情况下,你应该退回到自己的布线类型,让你的code调用到适当的构造函数,例如:
In case the UserAccountService
is part of a reusable library, you should prevent using your container's auto-wiring capabilities in that case as described here. In that case you should fallback to wiring the type yourself and let your code call into the proper constructor, for instance:
container.Register<UserAccountService<HierarchicalUserAccount>>(() =>
new UserAccountService<HierarchicalUserAccount>(
container.GetInstance<MembershipRebootConfiguration<HierarchicalUserAccount>>(),
container.GetInstance<IUserAccountRepository<HierarchicalUserAccount>>()));
这篇关于会员重启与简单的喷油器替代Ninject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!