i have asp.net mvc application i have created a custom membership provider he is bound in web.config like this:
<membership defaultProvider="MyMembershipProvider">
<providers>
<clear/>
<add name="MyMembershipProvider" type="MyProject.Infrastructure.Security.MyMembershipProvider" />
</providers>
</membership>
i use windsor castle for IoC
usually i use the contructor injection something like : SomeController(ISomething something) { something.do() ... }
but i can not use this for the custom membership class because i get a error from web.config that i don't have a parameterless constructor, and if i would the object wouldn't be initialized
so i used property injection like so:
<castle>
<components>
<component id="usersRepos"
service="MyProject.Core.Repositories.IUserRepository, MyProject.Core"
type="MyProject.Data.RepositoryImplementations, MyProject.Data">
</component>
...
public class MyMembershipProvider : MembershipProvider { public IUserRepository UserRepository{get; set;}
public override bool ValidateUser(string username, string password)
{
if (UserRepository.UserExists(username, password))
{
return true;
}
return false;
}
...
and i get object reference not found exception because the object (UserRepository) has not been initialized