Add application DbContext
This commit is contained in:
parent
767a857635
commit
d159cb9b00
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Company.WebApplication1.Data
|
||||||
|
{
|
||||||
|
public class ApplicationDbContext : IdentityDbContext
|
||||||
|
{
|
||||||
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||||
|
: base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
|
@ -12,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
namespace Company.WebApplication1.Data.Migrations
|
namespace Company.WebApplication1.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(IdentityDbContext))]
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
[Migration("00000000000000_CreateIdentitySchema")]
|
[Migration("00000000000000_CreateIdentitySchema")]
|
||||||
partial class CreateIdentitySchema
|
partial class CreateIdentitySchema
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
|
@ -12,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
namespace Company.WebApplication1.Data.Migrations
|
namespace Company.WebApplication1.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(IdentityDbContext))]
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
partial class IdentityDbContextModelSnapshot : ModelSnapshot
|
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|
@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
#endif
|
#endif
|
||||||
#if (OrganizationalAuth || IndividualAuth)
|
#if (OrganizationalAuth || IndividualAuth)
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
@ -26,6 +25,7 @@ using Microsoft.AspNetCore.Mvc.Authorization;
|
||||||
#endif
|
#endif
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Company.WebApplication1.Data;
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -57,20 +57,16 @@ namespace Company.WebApplication1
|
||||||
});
|
});
|
||||||
|
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
services.AddDbContext<IdentityDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
#if (UseLocalDB)
|
#if (UseLocalDB)
|
||||||
options.UseSqlServer(
|
options.UseSqlServer(
|
||||||
Configuration.GetConnectionString("DefaultConnection"),
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1")
|
#else
|
||||||
));
|
|
||||||
#else
|
|
||||||
options.UseSqlite(
|
options.UseSqlite(
|
||||||
Configuration.GetConnectionString("DefaultConnection"),
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1")
|
#endif
|
||||||
));
|
|
||||||
#endif
|
|
||||||
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
|
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
|
||||||
.AddEntityFrameworkStores<IdentityDbContext>()
|
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||||
.AddDefaultUI()
|
.AddDefaultUI()
|
||||||
.AddDefaultTokenProviders();
|
.AddDefaultTokenProviders();
|
||||||
|
|
||||||
|
|
@ -80,24 +76,15 @@ namespace Company.WebApplication1
|
||||||
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||||
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
|
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
|
||||||
})
|
})
|
||||||
#if (OrganizationalAuth)
|
#if (OrganizationalAuth)
|
||||||
.AddAzureAd(options => Configuration.Bind("AzureAd", options))
|
.AddAzureAd(options => Configuration.Bind("AzureAd", options))
|
||||||
#elif (IndividualB2CAuth)
|
#elif (IndividualB2CAuth)
|
||||||
.AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options))
|
.AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options))
|
||||||
#endif
|
#endif
|
||||||
.AddCookie();
|
.AddCookie();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if (IndividualLocalAuth)
|
#if (OrganizationalAuth)
|
||||||
services.AddMvc()
|
|
||||||
.AddRazorPagesOptions(options =>
|
|
||||||
{
|
|
||||||
options.Conventions.AuthorizeFolder("/Account/Manage");
|
|
||||||
options.Conventions.AuthorizePage("/Account/Logout");
|
|
||||||
})
|
|
||||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
|
||||||
|
|
||||||
#elif (OrganizationalAuth)
|
|
||||||
services.AddMvc(options =>
|
services.AddMvc(options =>
|
||||||
{
|
{
|
||||||
var policy = new AuthorizationPolicyBuilder()
|
var policy = new AuthorizationPolicyBuilder()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Company.WebApplication1.Data
|
||||||
|
{
|
||||||
|
public class ApplicationDbContext : IdentityDbContext
|
||||||
|
{
|
||||||
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||||
|
: base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
|
@ -12,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
namespace Company.WebApplication1.Data.Migrations
|
namespace Company.WebApplication1.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(IdentityDbContext))]
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
[Migration("00000000000000_CreateIdentitySchema")]
|
[Migration("00000000000000_CreateIdentitySchema")]
|
||||||
partial class CreateIdentitySchema
|
partial class CreateIdentitySchema
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
|
@ -12,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
namespace Company.WebApplication1.Data.Migrations
|
namespace Company.WebApplication1.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(IdentityDbContext))]
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
partial class IdentityDbContextModelSnapshot : ModelSnapshot
|
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|
@ -10,13 +10,13 @@ using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
using Microsoft.AspNetCore.HttpsPolicy;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Company.WebApplication1.Data;
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -42,21 +42,17 @@ namespace Company.WebApplication1
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
services.AddDbContext<IdentityDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
#if (UseLocalDB)
|
#if (UseLocalDB)
|
||||||
options.UseSqlServer(
|
options.UseSqlServer(
|
||||||
Configuration.GetConnectionString("DefaultConnection"),
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1")
|
|
||||||
));
|
|
||||||
#else
|
#else
|
||||||
options.UseSqlite(
|
options.UseSqlite(
|
||||||
Configuration.GetConnectionString("DefaultConnection"),
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1")
|
|
||||||
));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
|
services.AddIdentity<IdentityUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
|
||||||
.AddEntityFrameworkStores<IdentityDbContext>()
|
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||||
.AddDefaultUI()
|
.AddDefaultUI()
|
||||||
.AddDefaultTokenProviders();
|
.AddDefaultTokenProviders();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue