How to configure Ninject for MVC4 & custom Membership provide?

前端 未结 3 1698
庸人自扰
庸人自扰 2020-12-20 03:41

According to this article description custom-membership-provider-with-repository-injection

I implement the custom Membership provide with inject.

Cu

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 04:01

    Since a custom RoleProvider often comes along with the custom MembershipProvider, in that case it is useful to add an injection for the Role Provider class. I used the ramon22's solution with an additional line.

    [assembly: WebActivator.PreApplicationStartMethod(typeof(TopRankFantasy.App_Start.NinjectMVC3), "Start")]
    [assembly: WebActivator.PostApplicationStartMethod(typeof(TopRankFantasy.App_Start.NinjectMVC3), "RegisterMembership")]
    [assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(TopRankFantasy.App_Start.NinjectMVC3), "Stop")]
    
    public static void RegisterMembership()
    {
        bootstrapper.Kernel.Inject(Membership.Provider);
        bootstrapper.Kernel.Inject(Roles.Provider);
    } 
    

提交回复
热议问题