asp.net MVC3 Ninject.Web.Common的注入提供程序

时间:2013-03-27 02:57:57

标签: asp.net asp.net-mvc-3 code-injection

我将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.
}

自定义提供程序注入我该怎么办?

1 个答案:

答案 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;}
    }
}