Frage

Here is my setup:

I have modeled my application after the SportsStore in Pro ASP.NET MVC3 Framework book.

For those that don't have the book:

I have 2 projects bundled in a solution -

--Project.Domain--

  Abstract(folder)
  ..IObjectRepository.cs

  Concrete(folder)
  ..EFObjectRepository.cs

  Entities(folder)
  ..Data.cs - contains class definition for Object

--Project.WebUI--

  Areas(folder)
  ..Area1
  ..Area2

  Infrastructure(folder)
  ..NinjectControllerFactory.cs

My question is how do I organize a custom membership provider with Ninject, with the way my app is currently structured?

Please provide code in C# and explain where each file should exist in my structure.

Please also provide all methods for account creation within the CustomMembershipProvider.

If you would like any additional info please let me know.

Thanks in advance for preventing insanity.

War es hilfreich?

Lösung

If you want to supply your own implementation of IAuthProvider you need to do the following:

  • Add your custom class to SportsStore.WebUI\Infrastructure\Concrete and let it inherit from IAuthProvider

    public class MyCustomAuthProvider : IAuthProvider { public bool Authenticate(string username, string password) { // Implement this function with your custom logic throw new NotImplementedException(); } }

  • In the NinjectControllerFactory change the binding:

Change

ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>();

To

ninjectKernel.Bind<IAuthProvider>().To<MyCustomAuthProvider>();

This will change your dependency injection. The AccountController will now use your custom implementation.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top