带有StructureMap和OWIN身份验证的ASP.NET MVC5

时间:2015-02-17 21:59:21

标签: asp.net-mvc dependency-injection structuremap owin asp.net-mvc-5.2

我继承了一个使用Owin身份验证和类似bootstraps的应用程序(通过PreApplicationStartMethod属性)

    public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
            app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
        }
    }

我已经介绍了一般工作正常的StructureMap.MVC5但不是ApplicationUserManager, ApplicationSignInManager & ApplicationRoleManager.的情况下如何解决这个问题,以便用Create调用这些类的IOwinContext方法和IdentityFactoryOptions。我知道我需要以某种方式将Owin解析器桥接到结构图,但我不确定具体如何?

0 个答案:

没有答案