Dependencies not getting injected properly mvc 5, owin, unity
<p>I am working with ASP.NET MVC 5, EF6, ASP.NET Identity and Unity as IoC, and I want to use the functionalities provided by the Identity framework for manipulation with users and registration as I am building a website.</p>

<p><strong>Startup.cs</strong></p>

<pre><code>public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }

    public void ConfigureAuth(IAppBuilder app)
    {
        // Configure the db context, user manager and signin manager to use a single instance per request
        app.CreatePerOwinContext(DbContext.Create);
        app.CreatePerOwinContext&lt;ApplicationUserManager&gt;(ApplicationUserManager.Create);
        app.CreatePerOwinContext&lt;ApplicationSignInManager&gt;(ApplicationSignInManager.Create);
        app.CreatePerOwinContext&lt;ApplicationRoleManager&gt;(ApplicationRoleManager.Create);



        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Auth/Login"),
            Provider = new CookieAuthenticationProvider
             {
                 // Enables the application to validate the security stamp when the user logs in.
                 // This is a security feature which is used when you change a password or add an external login to your account.  
                 OnValidateIdentity = SecurityStampValidator.OnValidateIdentity&lt;ApplicationUserManager, ApplicationUser&gt;(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) =&gt; user.GenerateUserIdentityAsync(manager))
             }
        });
    }



}
</code></pre>

<p><strong>IdentityConfig.cs</strong></p>

<pre><code>public class EmailService : IIdentityMessageService
    {
        public async Task SendAsync(IdentityMessage message)
        {
            await configSendGridasync(message);
        }

    private async Task configSendGridasync(IdentityMessage message)
    {
        var myMessage = new SendGridMessage();
        myMessage.AddTo(message.Destination);
        myMessage.From = new System.Net.Mail.MailAddress("John@Smith.ko", "JOhn Smith");
        myMessage.Subject = message.Subject;
        myMessage.Text = message.Body;
        myMessage.Html = message.Body;

        var creds = new NetworkCredential("user", "pass");

        var transport = new Web(creds);

        if (transport != null)
        {
            await transport.DeliverAsync(myMessage);
        }
        else
        {
            Trace.TraceError("Failed to create Web transport.");
            await Task.FromResult(0);
        }
    }
}


// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
{
    public ApplicationUserManager(IUserStore&lt;ApplicationUser&gt; store)
        : base(store)
    {
    }

    public static ApplicationUserManager Create(IdentityFactoryOptions&lt;ApplicationUserManager&gt; options, IOwinContext context)
    {
        var manager = new ApplicationUserManager(new UserStore&lt;ApplicationUser&gt;(context.Get&lt;DbContext&gt;()));
        // Configure validation logic for usernames
        manager.UserValidator = new UserValidator&lt;ApplicationUser&gt;(manager)
        {
            AllowOnlyAlphanumericUserNames = false,
            RequireUniqueEmail = true
        };

        // Configure validation logic for passwords
        manager.PasswordValidator = new PasswordValidator
        {
            RequiredLength = 6,
            RequireNonLetterOrDigit = false,
            RequireDigit = true,
            RequireLowercase = true,
            RequireUppercase = false,
        };

        // Configure user lockout defaults
        manager.UserLockoutEnabledByDefault = true;
        manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
        manager.MaxFailedAccessAttemptsBeforeLockout = 5;
        manager.EmailService = new EmailService();

        var dataProtectionProvider = options.DataProtectionProvider;
        if (dataProtectionProvider != null)
        {
            manager.UserTokenProvider =
                new DataProtectorTokenProvider&lt;ApplicationUser&gt;(dataProtectionProvider.Create("ASP.NET Identity"));

        }
        return manager;
    }
}

// Configure the application sign-in manager which is used in this application.
public class ApplicationSignInManager : SignInManager&lt;ApplicationUser, string&gt;
{
    public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
        : base(userManager, authenticationManager)
    {
    }

    public override Task&lt;ClaimsIdentity&gt; CreateUserIdentityAsync(ApplicationUser user)
    {
        return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
    }

    public static ApplicationSignInManager Create(IdentityFactoryOptions&lt;ApplicationSignInManager&gt; options, IOwinContext context)
    {
        return new ApplicationSignInManager(context.GetUserManager&lt;ApplicationUserManager&gt;(), context.Authentication);
    }
}

public class ApplicationRoleManager : RoleManager&lt;IdentityRole&gt;
{
    public ApplicationRoleManager(IRoleStore&lt;IdentityRole, string&gt; roleStore)
        : base(roleStore)
    {
    }
    public static ApplicationRoleManager Create(
        IdentityFactoryOptions&lt;ApplicationRoleManager&gt; options,
        IOwinContext context)
    {
        var manager = new ApplicationRoleManager(
            new RoleStore&lt;IdentityRole&gt;(
                context.Get&lt;DbContext&gt;()));

        return manager;
    }
}
</code></pre>

<p><strong>UnityConfig.cs</strong></p>

<pre><code>public class UnityConfig
    {
        #region Unity Container
        private static Lazy&lt;IUnityContainer&gt; container = new Lazy&lt;IUnityContainer&gt;(() =&gt;
        {
            var container = new UnityContainer();
            RegisterTypes(container);
            return container;
        });

    /// &lt;summary&gt;
    /// Gets the configured Unity container.
    /// &lt;/summary&gt;
    public static IUnityContainer GetConfiguredContainer()
    {
        return container.Value;
    }
    #endregion

    public static void RegisterTypes(IUnityContainer container)
    {
        #region AutoMapper DI
        var config = new MapperConfiguration(cfg =&gt;
        {
            cfg.AddProfile&lt;AutoMapperWebProfileConfiguration&gt;();
        });

        var mapper = config.CreateMapper();
        container.RegisterInstance(config.CreateMapper());

        #endregion

        #region userManager and roleManager DI 
        var accountInjectionConstructor = new InjectionConstructor(new DbContext());
        container.RegisterType&lt;IUserStore&lt;ApplicationUser&gt;, UserStore&lt;ApplicationUser&gt;&gt;(accountInjectionConstructor);
        container.RegisterType&lt;IRoleStore&lt;IdentityRole, string&gt;,
            RoleStore&lt;IdentityRole, string, IdentityUserRole&gt;&gt;(accountInjectionConstructor);

        #endregion

        #region AuthenticationManager
        container.RegisterType&lt;IAuthenticationManager&gt;(new InjectionFactory(o =&gt; HttpContext.Current.GetOwinContext().Authentication));

        #endregion
        #region IdentityConfig injects
        container.RegisterType&lt;DbContext&gt;();
        container.RegisterType&lt;ApplicationSignInManager&gt;();
        container.RegisterType&lt;ApplicationUserManager&gt;();
        container.RegisterType&lt;EmailService&gt;();
        container.RegisterType&lt;IMappingEngine&gt;(new InjectionFactory(_ =&gt; Mapper.Engine));
        #endregion


   }
}
</code></pre>

<p><strong>AuthController.cs</strong></p>

<pre><code>public class AuthController : Controller
{

    private IMapper mapper;
    private RoleManager&lt;IdentityRole&gt; roleManager;
    private IAuthenticationManager authManager;
    private ApplicationUserManager userManager;
    private ApplicationSignInManager signInManager;

    public AuthController(IMapper mapper, IRoleStore&lt;IdentityRole, string&gt; roleStore, IAuthenticationManager authManager, ApplicationUserManager userManager, ApplicationSignInManager signInManager)
    {
        this.mapper = mapper;
        this.roleManager = new RoleManager&lt;IdentityRole&gt;(roleStore);
        this.authManager = authManager;
        this.userManager = userManager;
        this.signInManager = signInManager;

    } //rest omitted for brevity.
</code></pre>

<p><strong>The problem</strong></p>

<p>When I run the code, everything in Startup.cs gets executed and all objects instantiated from the IdentityConfig.cs, so I get an instance of UserManager that has all the needed properties set (email service, userTokenprovider etc), but when my controller is reached, another object gets injected which does not have these properties set, hence I get many exceptions (e.g. IUserTokenProvider not registered etc). I assume that the UserManager that gets injected into the Controller is the one that Unity injects, and not the one that is created by Startup.cs. Same story with the rest private properties defined in the controller. 
How can I tell to Unity to use the objects created by the Startup.cs?</p>