To move the IdentityModel into a class library (which is the right thing to do according to the SRP), follow these steps:
Good to go!
- Create a class library. (ClassLibrary1)
- Using NuGet, add a reference to Microsoft.AspNet.Identity.EntityFramework. This will also auto-add some other references.
- Add a reference in your website to ClassLibrary1
- Find WebSite/Models/IdentityModel.cs and move it to ClassLibrary1.
- Make IdentityModel.cs look like this:
public class ApplicationUser : IdentityUser { } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("YourContextName") { } }
- Make sure your website's Web.config has YourContextName pointing
to the right database in the section. (Note: this database can and
should house your application data).
<add name="YourContextName" connectionString="YourConnectionStringGoesHere" providerName="System.Data.SqlClient" />
- Make your EF Context class inherit from your ApplicationDbContext:
public class YourContextName : ApplicationDbContext { public DbSet<ABizClass1> BizClass1 { get; set; } public DbSet<ABizClass2> BizClass2 { get; set; } // And so forth ... }
Good to go!
Nhận xét
Đăng nhận xét