How to inject repositories into a custom MembershipProvider?
Asked Answered
F

1

1

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!

Fraase answered 7/12, 2011 at 0:57 Comment(1)
Your're right that the reason is that Ninject isnt doing the creating of your MembershipProvider class. you can do a Kernel.Inject after the fact, but the real answer is to look harder around here for ninject and/or other DI frameworks integration with the membership provider is best done.Machinery
D
3

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.

Domineer answered 7/12, 2011 at 10:4 Comment(1)
alrigh im definitivly giving up on the provider then i will make my own i know how it work so that wont be a real problem.Fraase

© 2022 - 2024 — McMap. All rights reserved.