如何将存储库注入自定义MembershipProvider? [英] How to inject repositories into a custom MembershipProvider?

查看:71
本文介绍了如何将存储库注入自定义MembershipProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我无法使它正常工作.我做了一个自定义的MembershipProvider,我想在其中注入一个存储库,但是[Inject]属性不起作用.

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; }
...

我认为这是因为此类是在MVC应用程序运行之前创建的,这会导致实际的问题.与使用我自己的系统相比,尝试使用MembershipProvider遇到的问题更多.

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.

关于我的ninject配置,我正在使用App_Start目录方法.我所有的绑定看起来都是正确的,所以与绑定无关.

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.

感谢您的帮助!

推荐答案

ASP.NET提供程序不是为正确的依赖项注入而设计的.只有针对它们的解决方法.

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

要么必须为它们设置一个绑定,然后在使用它们之前解析至少一个实例.例如.通过将实例注入Global.asax或在首次使用(kernel.Inject(...))之前必须手动注入实例.再次很有可能是在global.asax应用程序的启动方法中.

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.

这篇关于如何将存储库注入自定义MembershipProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆