Search code examples
sql-serverentity-frameworkasp.net-mvc-5owin

Does new ASP.NET MVC identity framework work without Entity Framework and SQL Server?


I am new to ASP.NET MVC 5 and so I am trying to use it as much as possible to learn it by practice.

So I am thinking of using the new OWIN implementation of ASP.NET MVC to implement the authentication and authorization of my project. That said, I am building the project in a way that it can work with various types of databases.

So far I have used generic ADO.NET elements (e.g. DbDataReader etc) and I have refused to use any ORM. So I am wondering if I can go ahead with using the new identity system of ASP.NET or will I be bound to Entity Framework and SQL Server if I do so?


Solution

  • Not that simple. Not that hard either.

    You'll have to write your custom implementation of:

    1. IUserStore<TUser>
    2. IUserPasswordStore<TUser>
    3. IUserTwoFactorStore<TUser>
    4. IUserClaimStore<TUser>
    5. IRoleStore<TRole>
    6. IUserSecurityStampStore<TUser, string>
    7. IUserRoleStore<TUser, string>
    8. UserManager<TUser>

    Then create your own user implementation, from IUser<TKey>, like:

    public class MyUser : IUser<string>
    {
        public string Id { get; set; }
        public string UserName { get; set; }
    }
    

    Finally, from NuGet, remove AspNet.Identity.EntityFramework, which will remove EntityFramework too if you're not using it elsewhere.

    Wherever your code breaks, rewrite it to use your custom implementations.

    Tip

    Create a MyUserRepository which implements items from 1 to 7.

    Then, create a MyUserManager which implements item 8.

    It will be damn easy to wire that up in place of default AspNet.Identity.EntityFramework classes.