13
$\begingroup$

I've been reading various other questions about using but I don't see anything concrete with regards to using it with an existing database when the project is developed in tiers. For argument's sake, say the following is true:

  • Solution
    • WebUI
    • Services
      • UserService
    • Data
      • MyDbContext
    • Core
      • User

How can I specify User (from the Core project) to be the IUserStore for the new identity provider? Am I missing something, or does this all assume that the website and the membership database always reside in the same project(or there are strict references to the Microsoft.AspNet.Identity.* libraries wherever the models reside)?

Setting up a DbContext at the WebUI layer just for authentication (and tie it in to the "MyDbContext" with a service) seems hacky. Am i missing something, or was the team just planning on this being only used in simple applications?

And feedback would be appreciated.

More Information

if it's worth mentioning:

  • This would be a completely new solution; I do not have old/existing aspnet_* or webpages_* tables to worry about. I'm trying to take various other custom solutions and tie them in to one solid solution, so I'm open to a lot of options. However, I would like to keep things broken out by layer (if at all possible).
$\endgroup$
11
  • $\begingroup$ Is your existing DB having Membership tables from ASP.NET Membership framework? $\endgroup$ Commented Nov 8, 2013 at 16:54
  • $\begingroup$ For existing Membership Db, you shall take steps to migrate it to new ASP.NET Identity framework. asp.net/identity/overview/migrations/… $\endgroup$ Commented Nov 8, 2013 at 16:57
  • $\begingroup$ No (I assume you're referring to the AspNet* tables), but that isn't much different than SimpleMembership I assume (other than a more dynamic tie to which model is the user, the role, etc?)? $\endgroup$ Commented Nov 8, 2013 at 16:58
  • $\begingroup$ And so it's known, this would be a virgin application; No need to convert old/antiquated code, old tables, etc. I am familiar with and have worked with SimpleMembership in some of my later projects, but we're retiring those solutions (so no need to worry about bringing that over either). $\endgroup$ Commented Nov 8, 2013 at 17:01
  • 1
    $\begingroup$ @Artem: Indeed I have, but unfortunately, due to the way its written, decoupling the model from the actions remain difficult. $\endgroup$ Commented Jun 26, 2015 at 13:10

1 Answer 1

3
$\begingroup$

Asp.net Identity Framework is set of components helping application to work with User Identity. Core framework blocks are in Microsoft.AspNet.Identity.Core assembly. The second Microsoft.AspNet.Identity.EntityFramework is the data persistence implementation for the Core framework.

Now for the n-tier application, you can define your AppUser model in any project/assembly. You need to inherit it from the Microsoft.AspNet.Identity.EntityFramework.IdentityUser. So based on your approach, you need to reference particular assembly.

Same is for the MyDbContext. You must inherit from the currently only available Persistence Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext<TUser>. Your MyDbContext can be in other project/assembly. You need to refer to your AppUser assembly too in this project/assembly.

$\endgroup$
Sign up to request clarification or add additional context in comments.

3 Comments

Before down-voting read the complete question and its comments and then read answer. The answer given here fits the written context to my understanding.
Not sure I understand why it is required to inherit from IdentityUser here. As we can implement our own IUserStore which would use IUser implementation. That is in case we go without Identity.EntityFramework classes. Could you explain the necessity to inherit here? Thanks!
@Artem, you are right. If you are creating your own implementation, its not required to inherit from IdentityUser which is part of Microsoft.AspNet.Identity.EntityFramework. But if you are just customizing for the application using Microsoft.AspNet.Identity.EntityFramework, you must inherit from IdentityUser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.