Registering an Identity Framework Custom Site Using Simpleinjector for AccountController

I have a situation where I want to use a custom UserStore from the Identity system. So my controller looks something like this.

public AccountController()
: this(new UserManager<ApplicationUser>(new MyUserStore()))
{
}
public AccountController(UserManager<ApplicationUser> userManager)
{
      UserManager = userManager;
}

Now Simpleinjector does not allow the use of multiple constructors. It can allow to register these classes with only one constructor. How should I solve this when the situation is similar to the situation above. with registration Simpleinjector.

+4
source share
2 answers

. , , .

- - ? , ...

, SimpleInjector IUserStore ?

, , , AccountController, .

( App_Start/SimpleInjectorInitializer.cs) IUserStore : MyUserStore IUserManager, ...

container.Register<IUserStore, MyUserStore>();    
container.Register<IUserManager<ApplicationUser>, UserManager<ApplicationUser>>();
+5

:

public class ApplicationUserManager : UserManager<Users, Guid>
{
    public ApplicationUserManager(IUserStore<Users, Guid> Store)
        : base(Store)
    {        
    }
}

public class ApplicationUserStore 
    : UserStore<Users, Roles, Guid, UserLogins, UserRoles, Claims>,
    IUserStore<Users,Guid>
{
    public ApplicationUserStore(RemsContext Context)
        : base(Context)
    {          
    }
}

Simpleinjector Configuraiton,

container.RegisterPerWebRequest<DbContext, RemsContext>();

container.Register<UserManager<Users, Guid>, ApplicationUserManager>();
container.Register<RoleManager<Roles, Guid>, ApplicationRoleManager>();

container.Register<IUserStore<Users, Guid>, 
    UserStore<Users, Roles, Guid, UserLogins, UserRoles, Claims>>();
container.Register<IRoleStore<Roles, Guid>, RoleStore<Roles, Guid, UserRoles>>();

. RoleManager.

public AccountsController(ApplicationUserManager _userManager,
    ApplicationRoleManager _roleManager)
{
    this.UserManager = _userManager;           
    this.RoleManager = _roleManager;
}

@Steven @Baldy, , .

0

Source: https://habr.com/ru/post/1535514/


All Articles