Question

My IUserService is null, not sure what's going on. This is my AccountController:

private readonly ICustomMembershipProvider _membershipProvider;

public AccountController(ICustomMembershipProvider provider)
{
     _membershipProvider = provider;
}
//other code omitted

My CustomMembershipProvider:

public class CustomMembershipProvider : MembershipProvider, ICustomMembershipProvider
{
private IUserService _userService;

    public CustomMembershipProvider()
        : this(DependencyResolver.Current.GetService<IUserService>())
    {
    }

    public CustomMembershipProvider(IUserService userService)
    {
        _userService = userService;
    }
//other code omitted

When I try to register a user, and the following method is called, my _userService is null, and that's what is causing the error but not sure why it's happening.

public override MembershipUser GetUser(string username, bool userIsOnline)
{
    var tempUser = _userService.GetByName(username);
//other code omitted

All other dependencies get resolved successfully

Était-ce utile?

La solution

Adding this answer since I spent multiple hours trying to figure out what this error was referring to. My Project had this warning: Warning: Found conflicts between different versions of the same dependent assembly , since it was a warning I didn't pay attention to it. Well, apparently that was the root of all problems, my Project.Web was using Mvc 3.0, while my Project.Services was using Mvc 4.0, this is why the DependencyResolver.Current.GetService<IUserService>() was not working. After I rolled back my Project.Services to Mvc 3.0, my entire solution worked like a charm! Lesson learned: pay attention to warnings.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top