我将Ninject.Web.Common安装到Nugeto我的项目中。 (App_Start / NinjectWebCommon.cs)
NinjectWebCommon未注入自定义提供程序。
public class CustomMembershipProvider : MembershipProvider
{
private IUserRepository userRepository {get; set; } // User Table Db Context. Is injected into the injection I want here.
}
自定义提供程序注入我该怎么办?
答案 0 :(得分:1)
你必须让ninject做属性注入或构造函数注入。 即。
public class CustomMembershipProvider : MembershipProvider
{
private IUserRepository userRepository;
public CustomMembershipProvider(IUserRepository userRepository)
{
this.userRepository = userRepository;
}
}
或
public class CustomMembershipProvider : MembershipProvider
{
private IUserRepository userRepository;
[Inject]
public IUserRepository UserRepository
{
get{return userRepository;}
set{userRepository = value;}
}
}