Setup Simple Injector with ASP.NET Identity 2.2.1

7/5/2016 5:43 am
HOME ยป Web Development

So I've been trying to setup ASP.NET Identity 2.2.1 and I keep hitting roadblocks. For being something that is supposed to be auto-generated by the framework it sure seems complicated to configure. I think I'm almost there but I'm still having issues setting up IoC with Simple Injector.

I've been reading through other StackOverflow questions and blogs about these issues. Most of them seem out of date because they deal with ASP.NET Identity 1.0. Or they deal with other IoC frameworks and I just can't translate them to Simple Injector. I've used other IoC Frameworks but I'm new to Simple Injector.

1) I've placed all of the configuration code for ApplicationUserManager in it's constructor instead of in it's Create method.


public class ApplicationUserManager :
    public ApplicationUserManager(IUserStore<ApplicationUser>
        IdentityFactoryOptions<ApplicationUserManager> options)
        : base(store)
        // Configure validation logic for usernames
        UserValidator = new UserValidator<ApplicationUser>(this)
            AllowOnlyAlphanumericUserNames = false,
            RequireUniqueEmail = true
        // Configure validation logic for passwords
        PasswordValidator = new PasswordValidator
            RequiredLength = 8,
            RequireNonLetterOrDigit = true,
            RequireDigit = true,
            RequireLowercase = true,
            RequireUppercase = true,
        var dataProtectionProvider = options.DataProtectionProvider;
        if (dataProtectionProvider != null)
            UserTokenProvider = new
                dataProtectionProvider.Create("ASP.NET Identity"));

2) I've created a custom implementation of UserStore with nothing in it for the time being.


public class ApplicationUserStore :
    public ApplicationUserStore(ApplicationDbContext context)
        : base(context)

3) I've commented out both of the app.CreatePerOwinContext() lines in Startup.Auth.cs.

4) In AccountController I removed the empty constructor, the UserManager class, and Dispose method. I changed the Constructor to the follow:


public ISecureDataFormat<AuthenticationTicket>
AccessTokenFormat { get; private set; }
private ApplicationUserManager _applicationUserManager;

public AccountController(ApplicationUserManager
    ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
    _applicationUserManager = applicationUserManager;
    AccessTokenFormat = accessTokenFormat;

5) So finally, setting up Simple Injector IoC

Simple Injector

var container = new Container();



    () => HttpContext.Current.GetOwinContext().Authentication);

So the biggest problem is that with this setup, I get an error about ApplicationUserManager.

Additional information: The configuration is invalid. The following diagnostic warnings were reported: -[Lifestyle Mismatch] ApplicationUserManager (Web Request) depends on IdentityFactoryOptions (Transient).

Also, I know that the HttpContext will cause issues since it's not setup at this point. I'll have to setup some type of factory pattern for it.

So I'm looking for any kind of help on fixing this error, how to setup the factory, advice if I'm breaking any kind of design patterns / best practices, if I should even be using ASP.NET Identity, should I try the version of Identity in ASP.NET Core 1.0, etc. Feel free to tear this apart because I'm really struggling to figure this out.


Related to : Setup Simple Injector with ASP.NET Identity 2.2.1
Setup Simple Injector with ASP.NET Identity 2.2.1
7/5/2016 5:43 am by venom361 in Web Development

So I've been trying to setup ASP.NET Identity 2.2.1 and I keep hitting roadblocks. For being something that is supposed to be auto-generated by the framework it sure seems complicated to configure. I think I'm almost there but I'm still having issues setting up IoC with Simple Injector.

TAGS: Setup Simple Injector with Identity
Use different configurations with Simple Injector
by camt in Web Development

I'm using the Simple Injector Dependency Injection framework and it looks cool and nice. But after building a configuration and use it, now I want to know how to change from one configuration to another.

Scenario: Let's imagine I've set up a configuration in the Global Asax and I have

Simple injector and internal constructors
8/12/2014 1:00 pm by Prasant Jain in Web Development

I am working on a small class library and using Simple Injector for my DI. The class library has an access point (some sort of a service I guess) which is public and it has some internal services and repositories.

I saw that Simple Injector does not support con

How to configure Simple Injector IoC to use RavenDB
by Simon Capewell in Web Development

I'm using Simple Injector for an IOC in an MVC 3 web application. I am using RavenDB for the data storage. There are several considerations on using RavenDB in an mvc 3 application. I've searched some on how to wire-up an IoC to use RavenDB but haven't found out how to wire-up simple injector to

Simple Injector, Function Not Being Intercepted?
29/12/2014 2:00 am by CrimsonGore in Web Development

I am trying to have a cross cutting concern intercept my calls on my controller but for some reason they aren't being intercepted.

I am basically trying to get the example here to work: http://simpleinj

Migration Ninject -> Simple Injector
by MikeT in Web Development

We use Ninject in our project, but have some performance problems. It will be interesting to test the same project with Simple Injector.

Do you know some kind of guides that make the migration easier?

Replace Ninject with Simple Injector
by Steven Weber in Web Development

I've used Ninject for my application. Ninject is really simple and easy to learn, but its quite slow and I try to use another IoC to compare if its faster as with Ninject.

There are a lot of IoC containers for MVC3 and Simple Injector looks really good to me, but I've a lot of problem

Simple Injector vs Hiro vs Autofac
by South Korea in Web Development
I'm new to DI and IoC and I'm trying to decide which IoC container to learn. I've seen several performance comparisons in which the three containers referenced seem to perform very well. However, I have found no feature comparisons that included Hiro or Simple Injector. The community for Autofac see
Mediator pattern and contravariance with Simple Injector
12/1/2015 8:20 pm by The Merg in Web Development

This question originates from the fact that I'm trying to create a Simple Injector implementation for MediatR:

I'm having trouble while trying to resolve implementations of

Simple Injector in Onion Layer Architecture
26/11/2014 10:37 pm by frozentundra123456 in Web Development

I'm trying to find a good resource, advice, etc in a project I've taken on for myself at work.


When I started here we had a application that was part MVC part Webform (separate projects on solution) that was tightly coupled to it's DAL with business cod

Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2014 © All Rights Reserved .