Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structuremap x Asp.net Identity

I'm having problems to register some dependencies like this one.

No default Instance is registered and cannot be automatically determined for type 'IUserStore<ApplicationIdentityUser, Int32>'

There is no configuration specified for IUserStore<ApplicationIdentityUser, Int32>


1.) new UserManager`2(*Default of IUserStore<ApplicationIdentityUser, Int32>*)
2.) UserManager<ApplicationIdentityUser, Int32>
3.) Instance of UserManager<ApplicationIdentityUser, Int32>
4.) new ApplicationUserManager(*Default of UserManager<ApplicationIdentityUser, Int32>*, *Default of IAuthenticationManager*)
5.) MyClinic.Infra.Data.Identity.ApplicationUserManager
6.) Instance of MyClinic.Core.Identity.IApplicationUserManager (MyClinic.Infra.Data.Identity.ApplicationUserManager)
7.) new AccountController(*Default of IApplicationUserManager*)
8.) MyClinic.Web.Controllers.AccountController
9.) Instance of MyClinic.Web.Controllers.AccountController
10.) Container.GetInstance(MyClinic.Web.Controllers.AccountController)

Could someone help me ?

My account controller is:

public class AccountController : Controller
{
    private IApplicationUserManager _userManager;
    public AccountController(IApplicationUserManager userManager)
    {
        _userManager = userManager;
    }
}

My application user manager:

public class ApplicationUserManager : IApplicationUserManager
{
    private readonly UserManager<ApplicationIdentityUser, int> _userManager;
    private readonly IAuthenticationManager _authenticationManager;
    private bool _disposed;

    public ApplicationUserManager(UserManager<ApplicationIdentityUser, int> userManager, IAuthenticationManager authenticationManager)
    {
        _userManager = userManager;
        _authenticationManager = authenticationManager;
    }
}
like image 203
Líverton Oliveira Avatar asked Feb 28 '26 03:02

Líverton Oliveira


1 Answers

You need to add the following to your structuremap Container to work with Asp.net Identity.

For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
For<DbContext>().Use(() => new ApplicationDbContext());
For<IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication);

In addition, you will need to install the package

Microsoft.Owin.Host.SystemWeb

to get the extension method GetOwinContext() to appear on HttpContext.Current

like image 154
Rich Hildebrand Avatar answered Mar 04 '26 03:03

Rich Hildebrand