How to inject repositories into a custom MembershipProvider?

ぃ、小莉子 提交于 2019-12-24 08:42:51

问题


It seem i can't get this to work. I made a custom MembershipProvider and i want to inject a repository inside but the [Inject] property just doesnt work.

  public class PyrosphereMembershipProvider : MembershipProvider
    {
        [Inject]
        protected IDepositoireUtilisateur DepositoireUtilisateur { get; set; }

        [Inject]
        protected IDepositoireProfile DepositoireProfile { get; set; }
...

I think this is because this class are created way before the MVC application is running which cause the actual problem. I am getting more problem trying to use the membershipprovider than making my own system.

About my ninject configuration i am using the App_Start directory method. All my binding are correct ive looked so that nothing to do with my bindings.

Any help is appreciated!


回答1:


The ASP.NET Providers aren't designed for proper dependency injection. There are only workarounds for them.

Either you have to setup a binding for them and resolve atleast one instance before using them. E.g. by injecting an instance into the Global.asax or you have to Inject an instance manually before the first use (kernel.Inject(...)). Again most likely in the global.asax application start method.



来源:https://stackoverflow.com/questions/8409109/how-to-inject-repositories-into-a-custom-membershipprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!