gpt4 book ai didi

c# - Ninject.Extensions.Factory : cannot find binding

转载 作者:太空宇宙 更新时间:2023-11-03 21:54:58 25 4
gpt4 key购买 nike

我的 Ninject.MVC RegisterServices 中有以下行:

kernel.Load(new NinjectBllModule());
kernel.Bind<IMembershipLogicFactory>().ToFactory();

在我的模块中:

 Bind<IUserLogic<LoginUser>>().To<UserLogic>();
Bind<IRoleLogic<SimpleRole, LoginUser>>().To<RoleLogic>();

和我的 IMembershipLogicFactory:

public interface IMembershipLogicFactory
{
IUserLogic<TUser> GetUserLogic<TUser>() where TUser : UserBase;
IRoleLogic<TRole, TUser> GetRoleLogic<TRole, TUser>() where TRole : RoleBase<TUser> where TUser : UserBase<TRole>;
}

然而,当我注入(inject) IMembershipLogicFactory 并在其上调用 GetUserLogic() 时,出现以下错误:

Error activating IUserLogic{LoginUser}
No matching bindings are available, and the type is not self-bindable.
Activation path:
1) Request for IUserLogic{LoginUser}

而且我似乎找不到我做错了什么。

最佳答案

扩展使用以 Get 开头的方法解析命名绑定(bind)的约定。 GetUserLogic 因此会被翻译成

kernel.Get<IUserLogic<LoginUser>>("UserLogic");

没有定义绑定(bind)。只需使用另一个方法名称,例如 CreateUserLogic

关于c# - Ninject.Extensions.Factory : cannot find binding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12686944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com