diff --git a/docs/en/Tutorials/Part-1.md b/docs/en/Tutorials/Part-1.md index 7000e39d8c..d419fc8d27 100644 --- a/docs/en/Tutorials/Part-1.md +++ b/docs/en/Tutorials/Part-1.md @@ -142,28 +142,36 @@ public class BookStoreMongoDbContext : AbpMongoDbContext ### Map the Book Entity to a Database Table -Open `BookStoreDbContextModelCreatingExtensions.cs` file in the `Acme.BookStore.EntityFrameworkCore` project and add the mapping code for the `Book` entity. The final class should be the following: +Locate to `OnModelCreating` method in the `BookStoreDbContext` class and add the mapping code for the `Book` entity: ````csharp using Acme.BookStore.Books; -using Microsoft.EntityFrameworkCore; -using Volo.Abp; -using Volo.Abp.EntityFrameworkCore.Modeling; +... namespace Acme.BookStore.EntityFrameworkCore { - public static class BookStoreDbContextModelCreatingExtensions + public class BookStoreDbContext : + AbpDbContext, + IIdentityDbContext, + ITenantManagementDbContext { - public static void ConfigureBookStore(this ModelBuilder builder) + ... + + protected override void OnModelCreating(ModelBuilder builder) { - Check.NotNull(builder, nameof(builder)); + base.OnModelCreating(builder); + + /* Include modules to your migration db context */ + + builder.ConfigurePermissionManagement(); + ... /* Configure your own tables/entities inside here */ builder.Entity(b => { b.ToTable(BookStoreConsts.DbTablePrefix + "Books", - BookStoreConsts.DbSchema); + BookStoreConsts.DbSchema); b.ConfigureByConvention(); //auto configure for the base class props b.Property(x => x.Name).IsRequired().HasMaxLength(128); }); @@ -179,7 +187,7 @@ namespace Acme.BookStore.EntityFrameworkCore The startup solution is configured to use [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database. -Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore.DbMigrations` project and type the following command: +Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore` project and type the following command: ```bash dotnet ef migrations add Created_Book_Entity @@ -189,7 +197,7 @@ This will add a new migration class to the project: ![bookstore-efcore-migration](./images/bookstore-efcore-migration.png) -> If you are using Visual Studio, you may want to use `Add-Migration Created_Book_Entity -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore.DbMigrations` is the *Default Project* in PMC. +> If you are using Visual Studio, you may want to use `Add-Migration Created_Book_Entity -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore` is the *Default Project* in PMC. {{end}} diff --git a/docs/en/Tutorials/Part-10.md b/docs/en/Tutorials/Part-10.md index 09df003703..11fdd9b781 100644 --- a/docs/en/Tutorials/Part-10.md +++ b/docs/en/Tutorials/Part-10.md @@ -70,7 +70,7 @@ We prefer to **delete the database** {{if DB=="EF"}}(you can run the `Drop-Datab ### Update the EF Core Mapping -Open the `BookStoreDbContextModelCreatingExtensions` class under the `EntityFrameworkCore` folder of the `Acme.BookStore.EntityFrameworkCore` project and change the `builder.Entity` part as shown below: +Locate to `OnModelCreating` method in the `BookStoreDbContext` class that under the `EntityFrameworkCore` folder of the `Acme.BookStore.EntityFrameworkCore` project and change the `builder.Entity` part as shown below: ````csharp builder.Entity(b => @@ -88,7 +88,7 @@ builder.Entity(b => The startup solution is configured to use [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database. -Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore.DbMigrations` project and type the following command: +Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore` project and type the following command: ````bash dotnet ef migrations add Added_AuthorId_To_Book @@ -121,7 +121,7 @@ migrationBuilder.AddForeignKey( * Creates an index on the `AuthorId` field. * Declares the foreign key to the `AppAuthors` table. -> If you are using Visual Studio, you may want to use `Add-Migration Added_AuthorId_To_Book -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore.DbMigrations` is the *Default Project* in PMC. +> If you are using Visual Studio, you may want to use `Add-Migration Added_AuthorId_To_Book -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore` is the *Default Project* in PMC. {{end}} diff --git a/docs/en/Tutorials/Part-7.md b/docs/en/Tutorials/Part-7.md index 312255e74c..45820cde09 100644 --- a/docs/en/Tutorials/Part-7.md +++ b/docs/en/Tutorials/Part-7.md @@ -48,7 +48,7 @@ Open the `BookStoreDbContext` in the `Acme.BookStore.EntityFrameworkCore` projec public DbSet Authors { get; set; } ```` -Then open the `BookStoreDbContextModelCreatingExtensions` class in the same project and add the following lines to the end of the `ConfigureBookStore` method: +Then locate to the `OnModelCreating` method in `BookStoreDbContext` class in the same project and add the following lines to the end of the method: ````csharp builder.Entity(b => @@ -72,7 +72,7 @@ This is just like done for the `Book` entity before, so no need to explain again The startup solution is configured to use [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/). Since we've changed the database mapping configuration, we should create a new migration and apply changes to the database. -Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore.DbMigrations` project and type the following command: +Open a command-line terminal in the directory of the `Acme.BookStore.EntityFrameworkCore` project and type the following command: ````bash dotnet ef migrations add Added_Authors @@ -88,7 +88,7 @@ You can apply changes to the database using the following command, in the same c dotnet ef database update ```` -> If you are using Visual Studio, you may want to use `Add-Migration Added_Authors -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore.DbMigrations` is the *Default Project* in PMC. +> If you are using Visual Studio, you may want to use `Add-Migration Added_Authors -c BookStoreMigrationsDbContext` and `Update-Database -c BookStoreMigrationsDbContext` commands in the *Package Manager Console (PMC)*. In this case, ensure that {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} is the startup project and `Acme.BookStore.EntityFrameworkCore` is the *Default Project* in PMC. {{else if DB=="Mongo"}} diff --git a/docs/en/Tutorials/images/bookstore-efcore-migration-authors.png b/docs/en/Tutorials/images/bookstore-efcore-migration-authors.png index a702875c71..2cfb29f86f 100644 Binary files a/docs/en/Tutorials/images/bookstore-efcore-migration-authors.png and b/docs/en/Tutorials/images/bookstore-efcore-migration-authors.png differ diff --git a/docs/en/Tutorials/images/bookstore-efcore-migration.png b/docs/en/Tutorials/images/bookstore-efcore-migration.png index 9714e795e2..5c034f6e80 100644 Binary files a/docs/en/Tutorials/images/bookstore-efcore-migration.png and b/docs/en/Tutorials/images/bookstore-efcore-migration.png differ diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application/Volo/Abp/TenantManagement/TenantAppService.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Application/Volo/Abp/TenantManagement/TenantAppService.cs index b2cdb89b59..50a92bc751 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Application/Volo/Abp/TenantManagement/TenantAppService.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Application/Volo/Abp/TenantManagement/TenantAppService.cs @@ -4,6 +4,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Volo.Abp.Application.Dtos; using Volo.Abp.Data; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.MultiTenancy; using Volo.Abp.ObjectExtending; namespace Volo.Abp.TenantManagement @@ -14,15 +16,18 @@ namespace Volo.Abp.TenantManagement protected IDataSeeder DataSeeder { get; } protected ITenantRepository TenantRepository { get; } protected ITenantManager TenantManager { get; } + protected IDistributedEventBus DistributedEventBus { get; } public TenantAppService( ITenantRepository tenantRepository, ITenantManager tenantManager, - IDataSeeder dataSeeder) + IDataSeeder dataSeeder, + IDistributedEventBus distributedEventBus) { DataSeeder = dataSeeder; TenantRepository = tenantRepository; TenantManager = tenantManager; + DistributedEventBus = distributedEventBus; } public virtual async Task GetAsync(Guid id) @@ -63,10 +68,22 @@ namespace Volo.Abp.TenantManagement await CurrentUnitOfWork.SaveChangesAsync(); + await DistributedEventBus.PublishAsync( + new TenantCreatedEto + { + Id = tenant.Id, + Name = tenant.Name, + Properties = + { + { "AdminEmail", input.AdminEmailAddress }, + { "AdminPassword", input.AdminPassword } + } + }); + using (CurrentTenant.Change(tenant.Id, tenant.Name)) { //TODO: Handle database creation? - + // TODO: Seeder might be triggered via event handler. await DataSeeder.SeedAsync( new DataSeedContext(tenant.Id) .WithProperty("AdminEmail", input.AdminEmailAddress) diff --git a/npm/ng-packs/apps/dev-app/src/app/app.module.ts b/npm/ng-packs/apps/dev-app/src/app/app.module.ts index 94ebbb5cc0..e859df2232 100644 --- a/npm/ng-packs/apps/dev-app/src/app/app.module.ts +++ b/npm/ng-packs/apps/dev-app/src/app/app.module.ts @@ -9,7 +9,6 @@ import { ThemeSharedModule } from '@abp/ng.theme.shared'; import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { InspectorModule } from '@ngneat/inspector'; import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; import { NgxsModule } from '@ngxs/store'; import { environment } from '../environments/environment'; @@ -17,10 +16,7 @@ import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { APP_ROUTE_PROVIDER } from './route.provider'; -const INSPECTION_TOOLS = [ - NgxsLoggerPluginModule.forRoot({ disabled: true }), - InspectorModule.forRoot(), -]; +const INSPECTION_TOOLS = [NgxsLoggerPluginModule.forRoot({ disabled: true })]; @NgModule({ imports: [ diff --git a/npm/ng-packs/apps/dev-app/src/app/home/home.component.html b/npm/ng-packs/apps/dev-app/src/app/home/home.component.html index 067a74c50f..677ee2e37f 100644 --- a/npm/ng-packs/apps/dev-app/src/app/home/home.component.html +++ b/npm/ng-packs/apps/dev-app/src/app/home/home.component.html @@ -1,6 +1,6 @@
-