0

我将 Ninject.Web.Common 安装到我的项目中。(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.
}

自定义提供程序注入 我能做什么?

4

1 回答 1

1

您必须让 ninject 进行属性注入或构造函数注入。IE

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;}
    }
}
于 2013-03-27T03:06:04.497 回答