如何将存储库注入自定义 MembershipProvider 中?

发布于 12-20 01:09 字数 531 浏览 5 评论 0原文

看来我无法让这个工作。我制作了一个自定义 MembershipProvider,我想在其中注入一个存储库,但 [Inject] 属性不起作用。

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

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

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

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

任何帮助表示赞赏!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心2024-12-27 01:09:02

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

您必须为它们设置绑定并在使用它们之前解析至少一个实例。例如,通过将实例注入 Global.asax 或您必须在第一次使用之前手动注入实例(kernel.Inject(...))。同样最有可能在 global.asax 应用程序启动方法中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文