diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/AbpDeskConsoleDemoModule.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/AbpDeskConsoleDemoModule.cs index 466cc5c7e8..23f9c47460 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/AbpDeskConsoleDemoModule.cs +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/AbpDeskConsoleDemoModule.cs @@ -5,11 +5,15 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Modularity; namespace AbpDesk.ConsoleDemo { - [DependsOn(typeof(AbpDeskApplicationModule), typeof(AbpDeskEntityFrameworkCoreModule))] + [DependsOn( + typeof(AbpDeskApplicationModule), + typeof(AbpDeskEntityFrameworkCoreModule), + typeof(AbpIdentityEntityFrameworkCoreModule))] public class AbpDeskConsoleDemoModule : AbpModule { public override void ConfigureServices(IServiceCollection services) diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs index 7d6ca73396..fa7d1586da 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs @@ -17,6 +17,11 @@ namespace AbpDesk.ConsoleDemo .ServiceProvider .GetRequiredService() .List(); + + //application + // .ServiceProvider + // .GetRequiredService() + // .List(); Console.ReadLine(); diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs new file mode 100644 index 0000000000..40170088e4 --- /dev/null +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/UserLister.cs @@ -0,0 +1,25 @@ +using System; +using System.Linq; +using Volo.Abp.Identity; +using Volo.DependencyInjection; + +namespace AbpDesk.ConsoleDemo +{ + public class UserLister : ITransientDependency + { + private readonly IdentityUserManager _userManager; + + public UserLister(IdentityUserManager userManager) + { + _userManager = userManager; + } + + public void List() + { + foreach (var user in _userManager.Users.ToList()) + { + Console.WriteLine(user); + } + } + } +} \ No newline at end of file diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/project.json b/src/AbpDesk/AbpDesk.ConsoleDemo/project.json index 4f230b066b..f6285ebf40 100644 --- a/src/AbpDesk/AbpDesk.ConsoleDemo/project.json +++ b/src/AbpDesk/AbpDesk.ConsoleDemo/project.json @@ -20,7 +20,9 @@ "version": "1.1.0-preview4-final" }, "Microsoft.Extensions.Configuration.Json": "1.1.0", - "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0" + "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0", + "Volo.Abp.Identity": "1.0.0-*", + "Volo.Abp.Identity.EntityFrameworkCore": "1.0.0-*" }, "tools": { diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20161221194225_AbpIdentity_Initial_Migration.Designer.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20161221194225_AbpIdentity_Initial_Migration.Designer.cs new file mode 100644 index 0000000000..9bf48b52ba --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20161221194225_AbpIdentity_Initial_Migration.Designer.cs @@ -0,0 +1,242 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Volo.Abp.Identity.EntityFrameworkCore; + +namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations +{ + [DbContext(typeof(IdentityDbContext))] + [Migration("20161221194225_AbpIdentity_Initial_Migration")] + partial class AbpIdentity_Initial_Migration + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("IdentityRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("IdentityRoleClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("IdentityUsers"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("IdentityUserClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("LoginProvider"); + + b.Property("ProviderDisplayName"); + + b.Property("ProviderKey"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId", "LoginProvider", "ProviderKey") + .IsUnique(); + + b.ToTable("IdentityUserLogins"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("RoleId") + .IsRequired(); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId", "RoleId") + .IsUnique(); + + b.ToTable("IdentityUserRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("UserId") + .IsRequired(); + + b.Property("Value"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "LoginProvider", "Name") + .IsUnique(); + + b.ToTable("IdentityUserTokens"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Tokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20161221194225_AbpIdentity_Initial_Migration.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20161221194225_AbpIdentity_Initial_Migration.cs new file mode 100644 index 0000000000..95ecb64937 --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20161221194225_AbpIdentity_Initial_Migration.cs @@ -0,0 +1,232 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations +{ + public partial class AbpIdentity_Initial_Migration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "IdentityRoles", + columns: table => new + { + Id = table.Column(nullable: false), + ConcurrencyStamp = table.Column(nullable: true), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "IdentityUsers", + columns: table => new + { + Id = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false, defaultValue: 0), + ConcurrencyStamp = table.Column(nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false, defaultValue: false), + LockoutEnabled = table.Column(nullable: false, defaultValue: false), + LockoutEnd = table.Column(nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + PasswordHash = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false, defaultValue: false), + SecurityStamp = table.Column(nullable: true), + TwoFactorEnabled = table.Column(nullable: false, defaultValue: false), + UserName = table.Column(maxLength: 256, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "IdentityRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_IdentityRoleClaims_IdentityRoles_RoleId", + column: x => x.RoleId, + principalTable: "IdentityRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "IdentityUserClaims", + columns: table => new + { + Id = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_IdentityUserClaims_IdentityUsers_UserId", + column: x => x.UserId, + principalTable: "IdentityUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "IdentityUserLogins", + columns: table => new + { + Id = table.Column(nullable: false), + LoginProvider = table.Column(nullable: true), + ProviderDisplayName = table.Column(nullable: true), + ProviderKey = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityUserLogins", x => x.Id); + table.ForeignKey( + name: "FK_IdentityUserLogins_IdentityUsers_UserId", + column: x => x.UserId, + principalTable: "IdentityUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "IdentityUserRoles", + columns: table => new + { + Id = table.Column(nullable: false), + RoleId = table.Column(nullable: false), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityUserRoles", x => x.Id); + table.ForeignKey( + name: "FK_IdentityUserRoles_IdentityRoles_RoleId", + column: x => x.RoleId, + principalTable: "IdentityRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_IdentityUserRoles_IdentityUsers_UserId", + column: x => x.UserId, + principalTable: "IdentityUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "IdentityUserTokens", + columns: table => new + { + Id = table.Column(nullable: false), + LoginProvider = table.Column(nullable: true), + Name = table.Column(nullable: true), + UserId = table.Column(nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityUserTokens", x => x.Id); + table.ForeignKey( + name: "FK_IdentityUserTokens_IdentityUsers_UserId", + column: x => x.UserId, + principalTable: "IdentityUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "IdentityRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_IdentityRoleClaims_RoleId", + table: "IdentityRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "IdentityUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "IdentityUsers", + column: "NormalizedUserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_IdentityUserClaims_UserId", + table: "IdentityUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_IdentityUserLogins_UserId_LoginProvider_ProviderKey", + table: "IdentityUserLogins", + columns: new[] { "UserId", "LoginProvider", "ProviderKey" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_IdentityUserRoles_RoleId", + table: "IdentityUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_IdentityUserRoles_UserId_RoleId", + table: "IdentityUserRoles", + columns: new[] { "UserId", "RoleId" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_IdentityUserTokens_UserId_LoginProvider_Name", + table: "IdentityUserTokens", + columns: new[] { "UserId", "LoginProvider", "Name" }, + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "IdentityRoleClaims"); + + migrationBuilder.DropTable( + name: "IdentityUserClaims"); + + migrationBuilder.DropTable( + name: "IdentityUserLogins"); + + migrationBuilder.DropTable( + name: "IdentityUserRoles"); + + migrationBuilder.DropTable( + name: "IdentityUserTokens"); + + migrationBuilder.DropTable( + name: "IdentityRoles"); + + migrationBuilder.DropTable( + name: "IdentityUsers"); + } + } +} diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/IdentityDbContextModelSnapshot.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/IdentityDbContextModelSnapshot.cs new file mode 100644 index 0000000000..5a86b97493 --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/IdentityDbContextModelSnapshot.cs @@ -0,0 +1,241 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Volo.Abp.Identity.EntityFrameworkCore; + +namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations +{ + [DbContext(typeof(IdentityDbContext))] + partial class IdentityDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("IdentityRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("IdentityRoleClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("IdentityUsers"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("IdentityUserClaims"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("LoginProvider"); + + b.Property("ProviderDisplayName"); + + b.Property("ProviderKey"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId", "LoginProvider", "ProviderKey") + .IsUnique(); + + b.ToTable("IdentityUserLogins"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("RoleId") + .IsRequired(); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId", "RoleId") + .IsUnique(); + + b.ToTable("IdentityUserRoles"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("UserId") + .IsRequired(); + + b.Property("Value"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "LoginProvider", "Name") + .IsUnique(); + + b.ToTable("IdentityUserTokens"); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => + { + b.HasOne("Volo.Abp.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => + { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Tokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpDeskDefaultDbContextFactory.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpDeskDefaultDbContextFactory.cs new file mode 100644 index 0000000000..d72e71f529 --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpDeskDefaultDbContextFactory.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Volo.Abp.Identity.EntityFrameworkCore; + +namespace AbpDesk.EntityFrameworkCore +{ + /* This class is needed for EF Core command line tooling */ + + public class IdentityDefaultDbContextFactory : IDbContextFactory + { + public IdentityDbContext Create(DbContextFactoryOptions options) + { + var builder = new DbContextOptionsBuilder(); + builder.UseSqlServer("Server=localhost;Database=AbpDesk;Trusted_Connection=True;"); + return new IdentityDbContext(builder.Options); + } + } +} diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs new file mode 100644 index 0000000000..20fc9f3fda --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Identity.EntityFrameworkCore +{ + [DependsOn(typeof(AbpIdentityModule), typeof(AbpEntityFrameworkCoreModule))] + public class AbpIdentityEntityFrameworkCoreModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddAbpDbContext(); + services.AddDefaultEfCoreRepositories(); //TODO: Move this into AddAbpDbContext as optional which will have it's own options + services.AddAssemblyOf(); + } + } +} diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs index 630702b1fc..7866e18728 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs @@ -12,9 +12,11 @@ namespace Volo.Abp.Identity.EntityFrameworkCore /// Initializes a new instance of . /// /// The options to be used by a . - public IdentityDbContext(DbContextOptions options) + public IdentityDbContext(DbContextOptions options) : base(options) - { } + { + + } /// /// Gets or sets the of Users. @@ -59,6 +61,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore /// protected override void OnModelCreating(ModelBuilder builder) { + //TODO: Set Default Values for properties + builder.Entity(b => { b.ToTable("IdentityUsers"); @@ -72,6 +76,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore b.HasMany(u => u.Claims).WithOne().HasForeignKey(uc => uc.UserId).IsRequired(); b.HasMany(u => u.Logins).WithOne().HasForeignKey(ul => ul.UserId).IsRequired(); b.HasMany(u => u.Roles).WithOne().HasForeignKey(ur => ur.UserId).IsRequired(); + b.HasMany(u => u.Tokens).WithOne().HasForeignKey(ur => ur.UserId).IsRequired(); b.HasIndex(u => u.NormalizedUserName).HasName("UserNameIndex").IsUnique(); b.HasIndex(u => u.NormalizedEmail).HasName("EmailIndex"); @@ -95,23 +100,19 @@ namespace Volo.Abp.Identity.EntityFrameworkCore builder.Entity(b => { b.ToTable("IdentityUserClaims"); - - //TODO: Index? - //TODO: Foreign Keys? }); builder.Entity(b => { b.ToTable("IdentityRoleClaims"); - - //TODO: Index? - //TODO: Foreign Keys? }); builder.Entity(b => { b.ToTable("IdentityUserRoles"); + b.HasOne().WithMany().HasForeignKey(ur => ur.RoleId).IsRequired(); + b.HasIndex(r => new { r.UserId, r.RoleId }).IsUnique(); }); @@ -120,15 +121,13 @@ namespace Volo.Abp.Identity.EntityFrameworkCore b.ToTable("IdentityUserLogins"); b.HasIndex(l => new { l.UserId, l.LoginProvider, l.ProviderKey }).IsUnique(); - //TODO: Foreign Keys? }); builder.Entity(b => { b.ToTable("IdentityUserTokens"); - b.HasIndex(l => new {l.UserId, l.LoginProvider, l.Name}).IsUnique(); - //TODO: Foreign Keys? + b.HasIndex(l => new { l.UserId, l.LoginProvider, l.Name }).IsUnique(); }); } } diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/project.json b/src/Volo.Abp.Identity.EntityFrameworkCore/project.json index f36718bb3a..f347bc0b73 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/project.json +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/project.json @@ -5,6 +5,7 @@ "NETStandard.Library": "1.6.1", "Volo.Abp.EntityFrameworkCore": "1.0.0-*", "Microsoft.EntityFrameworkCore.Relational": "1.1.0", + "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Volo.Abp.Identity": "1.0.0-*" }, diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/AbpIdentityModule.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/AbpIdentityModule.cs new file mode 100644 index 0000000000..60133f0855 --- /dev/null +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/AbpIdentityModule.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Identity +{ + public class AbpIdentityModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddAssemblyOf(); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleManager.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleManager.cs index 25ba5dc270..3515733710 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleManager.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleManager.cs @@ -2,10 +2,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; +using Volo.Abp.Domain.Services; namespace Volo.Abp.Identity { - public class IdentityRoleManager : RoleManager + public class IdentityRoleManager : RoleManager, IDomainService { public IdentityRoleManager( IRoleStore store, diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs index 8d8930f80c..e8901e5047 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs @@ -103,6 +103,11 @@ namespace Volo.Abp.Identity /// public virtual ICollection Logins { get; } = new Collection(); + /// + /// Navigation property for this users tokens. + /// + public virtual ICollection Tokens { get; } = new Collection(); + protected IdentityUser() { diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserManager.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserManager.cs index b0d40a8fd1..c3bb1f2a97 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserManager.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserManager.cs @@ -4,10 +4,11 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Volo.Abp.Domain.Services; namespace Volo.Abp.Identity { - public class IdentityUserManager : UserManager + public class IdentityUserManager : UserManager, IDomainService { public IdentityUserManager( IUserStore store, diff --git a/src/Volo.Abp/Volo/Abp/Domain/Services/IDomainService.cs b/src/Volo.Abp/Volo/Abp/Domain/Services/IDomainService.cs new file mode 100644 index 0000000000..248c66c1d6 --- /dev/null +++ b/src/Volo.Abp/Volo/Abp/Domain/Services/IDomainService.cs @@ -0,0 +1,12 @@ +using Volo.DependencyInjection; + +namespace Volo.Abp.Domain.Services +{ + /// + /// This interface must be implemented by all domain services to identify them by convention. + /// + public interface IDomainService : ITransientDependency + { + + } +} \ No newline at end of file