I got the idea it would be good to split the website (mvc) part and the data part into 2 different projects. I also want to use a context per request (owin context if possible).
First real question: Why should or shouldn't I do this.
And the second question: I get an error the way i do it now. I can probebly solve it by installing the entity framework package from NuGet. But then i have the idea i will still be mixing things. The website then knows it uses Entity Framework.
Error: The type 'Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The code:
public static Login.Data.ApplicationUserManager CreateApplicationUserManager(IdentityFactoryOptions<Login.Data.ApplicationUserManager> options, IOwinContext context)
{
Login.Data.ApplicationUserManager manager = new Login.Data.ApplicationUserManager(context.Get<AppContext>());
return manager;
}
And the AppContext Class:
public class AppContext : IdentityDbContext<ApplicationUser>, IDisposable
{
public AppContext()
: base("MemberContext")
{
}
public static AppContext CreateAppContext()
{
return new AppContext();
}
}
Split asp.net Identity into 2 projects. First real question: Why should or shouldn't I do this.
You should definitely separate your Web Application from your Services and Database layer (so if you're going to split projects, you'll need 3 not 2). But you're missing the Services layer which would be responsible for retrieving and transforming database entities to business/domain objects and pass those objects to your Web Application (rather than database entities - which require EF).
And the second question: I get an error the way i do it now. I can probably solve it by installing the entity framework package from NuGet. But then i have the idea i will still be mixing things. The website then knows it uses Entity Framework.
If your web application accesses the data context directly, then it needs to know about Entity Framework and ASP.NET Identity for EF hence the error you're getting.
Create a Services layer (a new class library), reference your database project and add Entity Framework in that services layer, then use that layer to retrieve data from the database and transform those entities to business objects.
Pass the business objects (and not EF Entities) to your Web Application. Then in your Web Application, reference the Services class library.
This would be a good start.