I have an ASP.NET MVC3 project where I want to use a custom membership provider. I also want to use Unity to solve my dependency injection.
This is the code from Global.asax:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
var container = new UnityContainer();
container.RegisterType<IAuthentification, Authentification>();
container.RegisterType<IRepository, Repository>();
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
}
this is the code of my membership provider:
public class CustomMembershipProvider : MembershipProvider
{
[Dependency]
private IProveaRepository Repository { get; set; }
public override bool ValidateUser(string username, string password)
{
.....
}
The problem is that when I set a breakpoint on the ValidateUser method, I see that the Repository property is not initialized. But this design:
[Dependency]
private IProveaRepository Repository { get; set; }
for example, works great in controllers.
Does anyone know why this is so and what to do?
source
share