I use the asp.net identifier in my project and use the structure structure as a DI structure. the problem is that when I use constructor injection, then ApplicationUserManager did not configure all its members, for example, TokenProvider, ...
this is my ApplicationUserManager class:
public class ApplicationUserManager : UserManager<User, long> { public ApplicationUserManager(IUserStore<User, long> store) : base(store) { } public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) { var manager = new ApplicationUserManager(new CustomUserStore(context.Get<InsuranceManagementContext>())); // Configure the application user manager manager.UserValidator = new UserValidator<User, long>(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = false }; manager.PasswordValidator = new PasswordValidator { RequireDigit = true, RequiredLength = 8, RequireLowercase = false, RequireNonLetterOrDigit = true, RequireUppercase = false }; var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider<User, long>(dataProtectionProvider.Create("TEST")); } return manager; } }
this is the Startup.Auth class:
public partial class Startup {
and its my AccountController:
public class AccountController : BaseController { private ApplicationUserManager _userManager; public ApplicationUserManager UserManager { get { return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); } private set { _userManager = value; } } public AccountController(ApplicationUserManager userManager) { UserManager = userManager; } }
My question is: how can I configure my ApplicationUserManager using a structure? if I install it as the code below, it works, but I don't know if this is a good solution or not:
ObjectFactory.Initialize(x => { ... x.For<ApplicationUserManager>().Use(() => HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>()); ... });
please tell me if there is a better solution, and if this is normal, then what is the best term for? HttpContextScope, Singleton, ...?
dependency-injection asp.net-mvc structuremap asp.net-identity asp.net-identity-2
Mohammad zare
source share