My solution contains:
- FooBarAsp, an asp project (provides a UI for the application)
- FooBar, a class library (the application)
- FooBar.Tests, a test project (tests the application)
FooBar uses EF 6 Code First, and contains a number of models, and a DataContext
. FooBarAsp uses Microsoft's Identity framework for user authentication, and has an ApplicationDbContext
. Both contexts play nice and work as expected. Global.asax.cs should execute MigrateDatabaseToLatestVersion
(right?). FooBar.Tests should execute DropCreateDatabaseAlways
and won't care about migrations (right?).
Should I EnableMigrations in FooBarAsp, or FooBar? For both contexts?
After running EnableMigrations in FooBar (just for kicks), my __MigrationHistory table contains two InitialCreate rows, one with ContextKey=FooBar.Models.DataContext and the other with ContextKey=FooBarAsp.Models.ApplicationDbContext. So they're both being tracked already? If so, (and since I did not enable automatic migrations), do I need to explicitly run both MigrateDatabaseToLatestVersion<DataContext>
and MigrateDatabaseToLatestVersion<ApplicationDbContext>
in Global.asax.cs?
Edit
Why don't I want to move ApplicationUser
into FooBar and merge ApplicationDbContext
into DataContext
?
The stock ApplicationUser
that comes with ASP is a separate entity (and separate ApplicationDbContext
, which happens to point to the same database). ASP's ApplicationUser
and the Identity framework take care of authentication, registration, email verification, login, logout, passwords, password strength, passwords resetting, two factor authentication, cookies, sessions, external login from sources like facebook/google, etc. FooBar doesn't know or care about any of that. FooBar's User
s have a UserName, and ASP's ApplicationUser
s have a UserName. When a user logs in, I just look up Foobar's User
by UserName, and that's who is logged in. So when I create a new Blog
(where Blog
is a FooBar entity), the author is FooBar's User
(not ApplicationUser
). The end result is that FooBar is not a Web/Desktop/Console/iPhone/Android application. It's a library that any of those things can reference, interact with, and provide a user interface for. The point is that FooBar is not polluted or biased by any of those user interfaces.
So I don't want to move ApplicationUser
into FooBar because it's from the Microsoft.AspNet.Identity namespace, and FooBar doesn't know or care about ASP.NET (or WPF or whatever the interface happens to be).