From 8c44264cb57444d9d5cdec7ec3d078493542aed6 Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Wed, 29 Dec 2021 17:47:30 +0300 Subject: [PATCH 01/12] add abp packages to package jon --- npm/ng-packs/package.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/npm/ng-packs/package.json b/npm/ng-packs/package.json index eca26a6b0f..e49dbd2ce1 100644 --- a/npm/ng-packs/package.json +++ b/npm/ng-packs/package.json @@ -56,6 +56,17 @@ "@angular/platform-browser": "12.2.13", "@angular/platform-browser-dynamic": "12.2.13", "@angular/router": "12.2.13", + "@abp/ng.account": "~5.0.1", + "@abp/ng.account.core": "~5.0.1", + "@abp/ng.core": "~5.0.1", + "@abp/ng.feature-management": "~5.0.1", + "@abp/ng.identity": "~5.0.1", + "@abp/ng.permission-management": "~5.0.1", + "@abp/ng.schematics": "~5.0.1", + "@abp/ng.setting-management": "~5.0.1", + "@abp/ng.tenant-management": "~5.0.1", + "@abp/ng.theme.basic": "~5.0.1", + "@abp/ng.theme.shared": "~5.0.1", "@fortawesome/fontawesome-free": "^5.15.4", "@ng-bootstrap/ng-bootstrap": "11.0.0-beta.2", "@ngneat/spectator": "^8.0.3", From 5840dd3f27901f2c8a8919ee0e45d6d260da22a4 Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Wed, 29 Dec 2021 18:05:05 +0300 Subject: [PATCH 02/12] update broken test --- .../packages/core/src/lib/tests/dynamic-layout.component.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts index ba4fd361c2..2076be84b4 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts @@ -198,6 +198,5 @@ describe('DynamicLayoutComponent', () => { spectator.detectComponentChanges(); expect(spectator.query('abp-layout-empty')).toBeFalsy(); - expect(spectator.query('abp-dynamic-layout').children[0].tagName).toEqual('ROUTER-OUTLET'); }); }); From 9f9f503127dc5734a86814005776ce91fea1d8c7 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 30 Dec 2021 10:37:15 +0800 Subject: [PATCH 03/12] Enhanced `AbpHttpClientProxyServiceConvention`. Compatible with special situations. --- .../AbpHttpClientProxyServiceConvention.cs | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs b/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs index 656c361062..bb0db66509 100644 --- a/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs +++ b/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs @@ -21,6 +21,7 @@ namespace Volo.Abp.Http.Client.Web.Conventions public class AbpHttpClientProxyServiceConvention : AbpServiceConvention { protected readonly IClientProxyApiDescriptionFinder ClientProxyApiDescriptionFinder; + protected readonly List ControllerWithAttributeRoute; protected readonly List ActionWithAttributeRoute; public AbpHttpClientProxyServiceConvention( @@ -30,6 +31,7 @@ namespace Volo.Abp.Http.Client.Web.Conventions : base(options, conventionalRouteBuilder) { ClientProxyApiDescriptionFinder = clientProxyApiDescriptionFinder; + ControllerWithAttributeRoute = new List(); ActionWithAttributeRoute = new List(); } @@ -51,15 +53,6 @@ namespace Volo.Abp.Http.Client.Web.Conventions { controller.ControllerName = controller.ControllerName.RemovePostFix("ClientProxy"); - var moduleApiDescription = FindModuleApiDescriptionModel(controller); - - if (moduleApiDescription != null && !moduleApiDescription.RootPath.IsNullOrWhiteSpace()) - { - var selector = controller.Selectors.FirstOrDefault(); - selector?.EndpointMetadata.Add(new AreaAttribute(moduleApiDescription.RootPath)); - controller.RouteValues.Add(new KeyValuePair("area", moduleApiDescription.RootPath)); - } - var controllerApiDescription = FindControllerApiDescriptionModel(controller); if (controllerApiDescription != null && !controllerApiDescription.ControllerGroupName.IsNullOrWhiteSpace()) @@ -77,6 +70,14 @@ namespace Volo.Abp.Http.Client.Web.Conventions { RemoveEmptySelectors(controller.Selectors); + var moduleApiDescription = FindModuleApiDescriptionModel(controller); + if (moduleApiDescription != null && !moduleApiDescription.RootPath.IsNullOrWhiteSpace()) + { + var selector = controller.Selectors.FirstOrDefault(); + selector?.EndpointMetadata.Add(new AreaAttribute(moduleApiDescription.RootPath)); + controller.RouteValues.Add(new KeyValuePair("area", moduleApiDescription.RootPath)); + } + var controllerType = controller.ControllerType.AsType(); var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault(controllerType.GetTypeInfo()); if (remoteServiceAtt != null && !remoteServiceAtt.IsEnabledFor(controllerType)) @@ -111,15 +112,14 @@ namespace Volo.Abp.Http.Client.Web.Conventions return;; } + ControllerWithAttributeRoute.Add(controller); ActionWithAttributeRoute.Add(action); if (!action.Selectors.Any()) { var abpServiceSelectorModel = new SelectorModel { - AttributeRouteModel = new AttributeRouteModel( - new RouteAttribute(template: actionApiDescriptionModel.Url) - ), + AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(template: actionApiDescriptionModel.Url)), ActionConstraints = { new HttpMethodActionConstraint(new[] { actionApiDescriptionModel.HttpMethod }) } }; @@ -142,9 +142,7 @@ namespace Volo.Abp.Http.Client.Web.Conventions if (selector.AttributeRouteModel == null) { - selector.AttributeRouteModel = new AttributeRouteModel( - new RouteAttribute(template: actionApiDescriptionModel.Url) - ); + selector.AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(template: actionApiDescriptionModel.Url)); } if (!selector.ActionConstraints.OfType().Any()) @@ -157,14 +155,17 @@ namespace Volo.Abp.Http.Client.Web.Conventions protected virtual void ConfigureClientProxyApiExplorer(ControllerModel controller) { - if (controller.ApiExplorer.GroupName.IsNullOrEmpty()) + if (ControllerWithAttributeRoute.Contains(controller)) { - controller.ApiExplorer.GroupName = controller.ControllerName; - } + if (controller.ApiExplorer.GroupName.IsNullOrEmpty()) + { + controller.ApiExplorer.GroupName = controller.ControllerName; + } - if (controller.ApiExplorer.IsVisible == null) - { - controller.ApiExplorer.IsVisible = IsVisibleRemoteService(controller.ControllerType); + if (controller.ApiExplorer.IsVisible == null) + { + controller.ApiExplorer.IsVisible = IsVisibleRemoteService(controller.ControllerType); + } } foreach (var action in controller.Actions) From eae8d6340fe2a63cc6ccb78cf3675044d02edd02 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 30 Dec 2021 12:14:02 +0800 Subject: [PATCH 04/12] Publish event when uow completed, Resolve #11100 --- .../Distributed/LocalDistributedEventBus.cs | 56 ++++++++++++--- .../LocalDistributedEventBus_Test.cs | 72 ++++++++++++++++++- 2 files changed, 115 insertions(+), 13 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs index d5dd961802..3389c2d243 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Options; using Volo.Abp.Collections; using Volo.Abp.DependencyInjection; using Volo.Abp.EventBus.Local; +using Volo.Abp.Uow; namespace Volo.Abp.EventBus.Distributed { @@ -15,16 +16,19 @@ namespace Volo.Abp.EventBus.Distributed { private readonly ILocalEventBus _localEventBus; + protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IServiceScopeFactory ServiceScopeFactory { get; } protected AbpDistributedEventBusOptions AbpDistributedEventBusOptions { get; } public LocalDistributedEventBus( ILocalEventBus localEventBus, + IUnitOfWorkManager unitOfWorkManager, IServiceScopeFactory serviceScopeFactory, IOptions distributedEventBusOptions) { _localEventBus = localEventBus; + UnitOfWorkManager = unitOfWorkManager; ServiceScopeFactory = serviceScopeFactory; AbpDistributedEventBusOptions = distributedEventBusOptions.Value; Subscribe(distributedEventBusOptions.Value.Handlers); @@ -122,25 +126,57 @@ namespace Volo.Abp.EventBus.Distributed _localEventBus.UnsubscribeAll(eventType); } - public Task PublishAsync(TEvent eventData, bool onUnitOfWorkComplete = true) + public async Task PublishAsync(TEvent eventData, bool onUnitOfWorkComplete = true) where TEvent : class { - return _localEventBus.PublishAsync(eventData, onUnitOfWorkComplete); + await PublishAsync(typeof(TEvent), eventData, onUnitOfWorkComplete); } - public Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true) + public async Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true) { - return _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); + if (onUnitOfWorkComplete && UnitOfWorkManager.Current != null) + { + AddToUnitOfWork( + UnitOfWorkManager.Current, + new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext()) + ); + return; + } + + await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete: false); + } + + public async Task PublishAsync(TEvent eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) + where TEvent : class + { + await PublishAsync(typeof(TEvent), eventData, onUnitOfWorkComplete, useOutbox); } - - public Task PublishAsync(TEvent eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) where TEvent : class + + public async Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) { - return _localEventBus.PublishAsync(eventData, onUnitOfWorkComplete); + if (onUnitOfWorkComplete && UnitOfWorkManager.Current != null) + { + AddToUnitOfWork( + UnitOfWorkManager.Current, + new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext(), useOutbox) + ); + return; + } + + if (useOutbox && UnitOfWorkManager.Current != null) + { + UnitOfWorkManager.Current.OnCompleted(async() => { + await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete: false); + }); + return; + } + + await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete: false); } - public Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) + protected virtual void AddToUnitOfWork(IUnitOfWork unitOfWork, UnitOfWorkEventRecord eventRecord) { - return _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); + unitOfWork.AddOrReplaceDistributedEvent(eventRecord); } } -} \ No newline at end of file +} diff --git a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs index 5bea07fc44..9d768f1054 100644 --- a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs +++ b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs @@ -1,7 +1,9 @@ using System; using System.Threading.Tasks; +using Shouldly; using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.MultiTenancy; +using Volo.Abp.Uow; using Xunit; namespace Volo.Abp.EventBus.Distributed @@ -44,12 +46,12 @@ namespace Volo.Abp.EventBus.Distributed Assert.Equal(tenantId, MySimpleDistributedSingleInstanceEventHandler.TenantId); } - + [Fact] public async Task Should_Get_TenantId_From_EventEto_Extra_Property() { var tenantId = Guid.NewGuid(); - + DistributedEventBus.Subscribe(GetRequiredService()); await DistributedEventBus.PublishAsync(new MySimpleEto @@ -59,8 +61,72 @@ namespace Volo.Abp.EventBus.Distributed {"TenantId", tenantId.ToString()} } }); - + Assert.Equal(tenantId, MySimpleDistributedSingleInstanceEventHandler.TenantId); } + + [Fact] + public async Task Event_Should_Published_On_UnitOfWorkComplete() + { + var id = 0; + DistributedEventBus.Subscribe(data => + { + id = data.Value; + return Task.CompletedTask; + }); + + var unitOfWorkManager = GetRequiredService(); + using (var uow = unitOfWorkManager.Begin()) + { + await DistributedEventBus.PublishAsync(new MySimpleEventData(3), onUnitOfWorkComplete: true, useOutbox: false); + } + id.ShouldBe(0); + + using (var uow = unitOfWorkManager.Begin()) + { + await DistributedEventBus.PublishAsync(new MySimpleEventData(3), onUnitOfWorkComplete: true, useOutbox: false); + await uow.CompleteAsync(); + } + id.ShouldBe(3); + + id = 0; + using (var uow = unitOfWorkManager.Begin()) + { + await DistributedEventBus.PublishAsync(new MySimpleEventData(3), onUnitOfWorkComplete: false, useOutbox: false); + } + id.ShouldBe(3); + } + + [Fact] + public async Task Event_Should_Published_On_UnitOfWorkComplete_UseOutbox() + { + var id = 0; + DistributedEventBus.Subscribe(data => + { + id = data.Value; + return Task.CompletedTask; + }); + + var unitOfWorkManager = GetRequiredService(); + using (var uow = unitOfWorkManager.Begin()) + { + await DistributedEventBus.PublishAsync(new MySimpleEventData(3), onUnitOfWorkComplete: false, useOutbox: true); + } + id.ShouldBe(0); + + using (var uow = unitOfWorkManager.Begin()) + { + await DistributedEventBus.PublishAsync(new MySimpleEventData(3), onUnitOfWorkComplete: false, useOutbox: true); + await uow.CompleteAsync(); + } + id.ShouldBe(3); + + id = 0; + using (var uow = unitOfWorkManager.Begin()) + { + await DistributedEventBus.PublishAsync(new MySimpleEventData(3), onUnitOfWorkComplete: false, useOutbox: false); + } + id.ShouldBe(3); + } } } From b75b633e6d5c4da8e4b03d5068b9deb286695178 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 30 Dec 2021 15:21:33 +0800 Subject: [PATCH 05/12] Make generate-proxy.json files embedded --- .../Volo.Abp.Account.HttpApi.Client.csproj | 5 +++++ .../Volo.Blogging.Admin.HttpApi.Client.csproj | 5 +++++ .../Volo.Blogging.HttpApi.Client.csproj | 5 +++++ .../Volo.CmsKit.Admin.HttpApi.Client.csproj | 5 +++++ .../Volo.CmsKit.Common.HttpApi.Client.csproj | 5 +++++ .../Volo.CmsKit.HttpApi.Client.csproj | 5 +++++ .../Volo.CmsKit.Public.HttpApi.Client.csproj | 5 +++++ .../Volo.Docs.Admin.HttpApi.Client.csproj | 5 +++++ .../Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj | 5 +++++ .../Volo.Abp.FeatureManagement.HttpApi.Client.csproj | 5 +++++ .../Volo.Abp.Identity.HttpApi.Client.csproj | 5 +++++ .../Volo.Abp.PermissionManagement.HttpApi.Client.csproj | 5 +++++ .../Volo.Abp.SettingManagement.HttpApi.Client.csproj | 5 +++++ .../Volo.Abp.TenantManagement.HttpApi.Client.csproj | 5 +++++ 14 files changed, 70 insertions(+) diff --git a/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj index aef884dbe2..b42d191b62 100644 --- a/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj +++ b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj @@ -15,4 +15,9 @@ + + + + + diff --git a/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj b/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj index 55b11f728d..20fba0d22b 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj +++ b/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj @@ -15,4 +15,9 @@ + + + + + diff --git a/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj b/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj index 68b3775baa..941afd504f 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj +++ b/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj @@ -15,4 +15,9 @@ + + + + + diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj index 1fb91747a2..171bc7d71f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj @@ -13,4 +13,9 @@ + + + + + diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj index dd5b656fb6..e02fa708c7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj @@ -13,4 +13,9 @@ + + + + + diff --git a/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj index 1d2f34b26c..11b9ad7422 100644 --- a/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj @@ -14,4 +14,9 @@ + + + + + diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj index 74087990f5..bc4b6c59fd 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj @@ -13,4 +13,9 @@ + + + + + diff --git a/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj b/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj index 00b0e26d75..2344d6d3f9 100644 --- a/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj +++ b/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj @@ -16,4 +16,9 @@ + + + + + diff --git a/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj b/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj index ed9acfaf20..11e24755d7 100644 --- a/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj +++ b/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj @@ -15,4 +15,9 @@ + + + + + diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj index a6dd5772e8..1d52c65e1f 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj @@ -13,4 +13,9 @@ + + + + + diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj index 5bff2432a7..d2eff9ffd5 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj @@ -19,4 +19,9 @@ + + + + + diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj b/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj index a198deb9eb..e2bd86a8cf 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj @@ -19,4 +19,9 @@ + + + + + diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj b/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj index 26c0fd77f7..403605c1f5 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj @@ -13,4 +13,9 @@ + + + + + diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj b/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj index 6e60e283ad..3049906edb 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj @@ -19,4 +19,9 @@ + + + + + From a80bce697d65eb89e5b307b3054ec3479e1d9226 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 30 Dec 2021 15:31:17 +0800 Subject: [PATCH 06/12] Get the configured actions in advance. --- .../Volo/Abp/Options/PreConfigureActionList.cs | 9 ++++++++- .../Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs | 7 +++---- .../Volo/Abp/Hangfire/AbpHangfireModule.cs | 3 ++- .../src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs | 5 ++--- .../Versioning/AbpAspNetCoreMvcVersioningTestModule.cs | 6 +++--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs index 00222d6399..30b96eac2c 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs @@ -12,5 +12,12 @@ namespace Volo.Abp.Options action(options); } } + + public TOptions Configure() + { + var options = Activator.CreateInstance(); + Configure(options); + return options; + } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs index 1ad835c122..806d60bb13 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs @@ -11,18 +11,17 @@ namespace Volo.Abp.EventBus.Rebus { public override void ConfigureServices(ServiceConfigurationContext context) { - var options = context.Services.ExecutePreConfiguredActions();; - context.Services.AddTransient(typeof(IHandleMessages<>), typeof(RebusDistributedEventHandlerAdapter<>)); + var preActions = context.Services.GetPreConfigureActions(); Configure(rebusOptions => { - context.Services.ExecutePreConfiguredActions(rebusOptions); + preActions.Configure(rebusOptions); }); context.Services.AddRebus(configure => { - options.Configurer?.Invoke(configure); + preActions.Configure().Configurer?.Invoke(configure); return configure; }); } diff --git a/framework/src/Volo.Abp.HangFire/Volo/Abp/Hangfire/AbpHangfireModule.cs b/framework/src/Volo.Abp.HangFire/Volo/Abp/Hangfire/AbpHangfireModule.cs index 1628d2f37f..3cfe62f13d 100644 --- a/framework/src/Volo.Abp.HangFire/Volo/Abp/Hangfire/AbpHangfireModule.cs +++ b/framework/src/Volo.Abp.HangFire/Volo/Abp/Hangfire/AbpHangfireModule.cs @@ -13,9 +13,10 @@ namespace Volo.Abp.Hangfire public override void ConfigureServices(ServiceConfigurationContext context) { + var preActions = context.Services.GetPreConfigureActions(); context.Services.AddHangfire(configuration => { - context.Services.ExecutePreConfiguredActions(configuration); + preActions.Configure(configuration); }); } diff --git a/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs b/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs index a4a08ce274..4e92d7e3b5 100644 --- a/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs +++ b/framework/src/Volo.Abp.Json/Volo/Abp/Json/AbpJsonModule.cs @@ -16,12 +16,11 @@ namespace Volo.Abp.Json context.Services.TryAddEnumerable(ServiceDescriptor .Transient, AbpSystemTextJsonSerializerOptionsSetup>()); + var preActions = context.Services.GetPreConfigureActions(); Configure(options => { options.Providers.Add(); - - var abpJsonOptions = context.Services.ExecutePreConfiguredActions(); - if (abpJsonOptions.UseHybridSerializer) + if (preActions.Configure().UseHybridSerializer) { options.Providers.Add(); } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs index 4e28d77a0a..8e7ed9bba2 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs @@ -38,9 +38,10 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning public override void ConfigureServices(ServiceConfigurationContext context) { + var preActions = context.Services.GetPreConfigureActions(); Configure(options => { - context.Services.ExecutePreConfiguredActions(options); + preActions.Configure(options); }); context.Services.AddAbpApiVersioning(options => @@ -51,8 +52,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning //options.ApiVersionReader = new HeaderApiVersionReader("api-version"); //Supports header too //options.ApiVersionReader = new MediaTypeApiVersionReader(); //Supports accept header too - var mvcOptions = context.Services.ExecutePreConfiguredActions(); - options.ConfigureAbp(mvcOptions); + options.ConfigureAbp(preActions.Configure()); }); context.Services.AddHttpClientProxies(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly); From d7503ba0eab56a42e25d6fa14474302dad5d4cb7 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 30 Dec 2021 15:21:33 +0800 Subject: [PATCH 07/12] Revert "Make generate-proxy.json files embedded" This reverts commit b75b633e6d5c4da8e4b03d5068b9deb286695178. --- .../Volo.Abp.Account.HttpApi.Client.csproj | 5 ----- .../Volo.Blogging.Admin.HttpApi.Client.csproj | 5 ----- .../Volo.Blogging.HttpApi.Client.csproj | 5 ----- .../Volo.CmsKit.Admin.HttpApi.Client.csproj | 5 ----- .../Volo.CmsKit.Common.HttpApi.Client.csproj | 5 ----- .../Volo.CmsKit.HttpApi.Client.csproj | 5 ----- .../Volo.CmsKit.Public.HttpApi.Client.csproj | 5 ----- .../Volo.Docs.Admin.HttpApi.Client.csproj | 5 ----- .../Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj | 5 ----- .../Volo.Abp.FeatureManagement.HttpApi.Client.csproj | 5 ----- .../Volo.Abp.Identity.HttpApi.Client.csproj | 5 ----- .../Volo.Abp.PermissionManagement.HttpApi.Client.csproj | 5 ----- .../Volo.Abp.SettingManagement.HttpApi.Client.csproj | 5 ----- .../Volo.Abp.TenantManagement.HttpApi.Client.csproj | 5 ----- 14 files changed, 70 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj index b42d191b62..aef884dbe2 100644 --- a/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj +++ b/modules/account/src/Volo.Abp.Account.HttpApi.Client/Volo.Abp.Account.HttpApi.Client.csproj @@ -15,9 +15,4 @@ - - - - - diff --git a/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj b/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj index 20fba0d22b..55b11f728d 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj +++ b/modules/blogging/src/Volo.Blogging.Admin.HttpApi.Client/Volo.Blogging.Admin.HttpApi.Client.csproj @@ -15,9 +15,4 @@ - - - - - diff --git a/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj b/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj index 941afd504f..68b3775baa 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj +++ b/modules/blogging/src/Volo.Blogging.HttpApi.Client/Volo.Blogging.HttpApi.Client.csproj @@ -15,9 +15,4 @@ - - - - - diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj index 171bc7d71f..1fb91747a2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi.Client/Volo.CmsKit.Admin.HttpApi.Client.csproj @@ -13,9 +13,4 @@ - - - - - diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj index e02fa708c7..dd5b656fb6 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi.Client/Volo.CmsKit.Common.HttpApi.Client.csproj @@ -13,9 +13,4 @@ - - - - - diff --git a/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj index 11b9ad7422..1d2f34b26c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.HttpApi.Client/Volo.CmsKit.HttpApi.Client.csproj @@ -14,9 +14,4 @@ - - - - - diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj index bc4b6c59fd..74087990f5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/Volo.CmsKit.Public.HttpApi.Client.csproj @@ -13,9 +13,4 @@ - - - - - diff --git a/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj b/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj index 2344d6d3f9..00b0e26d75 100644 --- a/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj +++ b/modules/docs/src/Volo.Docs.Admin.HttpApi.Client/Volo.Docs.Admin.HttpApi.Client.csproj @@ -16,9 +16,4 @@ - - - - - diff --git a/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj b/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj index 11e24755d7..ed9acfaf20 100644 --- a/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj +++ b/modules/docs/src/Volo.Docs.HttpApi.Client/Volo.Docs.HttpApi.Client.csproj @@ -15,9 +15,4 @@ - - - - - diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj index 1d52c65e1f..a6dd5772e8 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi.Client/Volo.Abp.FeatureManagement.HttpApi.Client.csproj @@ -13,9 +13,4 @@ - - - - - diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj index d2eff9ffd5..5bff2432a7 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo.Abp.Identity.HttpApi.Client.csproj @@ -19,9 +19,4 @@ - - - - - diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj b/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj index e2bd86a8cf..a198deb9eb 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi.Client/Volo.Abp.PermissionManagement.HttpApi.Client.csproj @@ -19,9 +19,4 @@ - - - - - diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj b/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj index 403605c1f5..26c0fd77f7 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.HttpApi.Client/Volo.Abp.SettingManagement.HttpApi.Client.csproj @@ -13,9 +13,4 @@ - - - - - diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj b/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj index 3049906edb..6e60e283ad 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.HttpApi.Client/Volo.Abp.TenantManagement.HttpApi.Client.csproj @@ -19,9 +19,4 @@ - - - - - From cb0b7233eafcb87c1d6c4f13b5c2868074e8521c Mon Sep 17 00:00:00 2001 From: Luke Ni Date: Thu, 30 Dec 2021 15:53:09 +0800 Subject: [PATCH 08/12] translate to zh-Hans --- docs/zh-Hans/Tutorials/Part-7.md | 239 +++++++++++++++++- .../bookstore-efcore-migration-authors.png | Bin 0 -> 7937 bytes 2 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 docs/zh-Hans/Tutorials/images/bookstore-efcore-migration-authors.png diff --git a/docs/zh-Hans/Tutorials/Part-7.md b/docs/zh-Hans/Tutorials/Part-7.md index 602306c484..95b016e451 100644 --- a/docs/zh-Hans/Tutorials/Part-7.md +++ b/docs/zh-Hans/Tutorials/Part-7.md @@ -1 +1,238 @@ -TODO.. \ No newline at end of file +# Web应用程序开发教程 - 第七章: 数据库集成 +````json +//[doc-params] +{ + "UI": ["MVC","Blazor","BlazorServer","NG"], + "DB": ["EF","Mongo"] +} +```` +## 关于本教程 + +在本系列教程中, 你将构建一个名为 `Acme.BookStore` 的用于管理书籍及其作者列表的基于ABP的应用程序. 它是使用以下技术开发的: + +* **{{DB_Text}}** 做为ORM提供程序. +* **{{UI_Value}}** 做为UI框架. + +本教程分为以下部分: + +- [Part 1: 创建服务端](Part-1.md) +- [Part 2: 图书列表页面](Part-2.md) +- [Part 3: 创建,更新和删除图书](Part-2.md) +- [Part 4: 集成测试](Part-4.md) +- [Part 5: 授权](Part-5.md) +- [Part 6: 作者: 领域层](Part-6.md) +- **Part 7: 数据库集成**(本章) +- [Part 8: 作者: 应用服务层](Part-8.md) +- [Part 9: 作者: 用户页面](Part-9.md) +- [Part 10: 图书到作者的关系](Part-10.md) + +## 下载源码 + +本教程根据你的**UI** 和 **数据库**偏好有多个版本,我们准备了几种可供下载的源码组合: + +* [MVC (Razor Pages) UI 与 EF Core](https://github.com/abpframework/abp-samples/tree/master/BookStore-Mvc-EfCore) +* [Blazor UI 与 EF Core](https://github.com/abpframework/abp-samples/tree/master/BookStore-Blazor-EfCore) +* [Angular UI 与 MongoDB](https://github.com/abpframework/abp-samples/tree/master/BookStore-Angular-MongoDb) + +> 如果你在Windows中遇到 "文件名太长" or "解压错误", 很可能与Windows最大文件路径限制有关. Windows文件路径的最大长度为250字符. 为了解决这个问题,参阅 [在Windows 10中启用长路径](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later). + +> 如果你遇到与Git相关的长路径错误, 尝试使用下面的命令在Windows中启用长路径. 参阅 https://github.com/msysgit/msysgit/wiki/Git-cannot-create-a-file-or-directory-with-a-long-path +> `git config --system core.longpaths true` + +## 简介 + +这章阐述如何为前一章介绍的 `作者` 实体配置数据库集成. + +{{if DB=="EF"}} + +## DB Context + +打开 `Acme.BookStore.EntityFrameworkCore` 项目中的 `BookStoreDbContext` 加入 `DbSet` 属性: + +````csharp +public DbSet Authors { get; set; } +```` + +定位到相同项目中的 `BookStoreDbContext` 类中的 `OnModelCreating` 方法, 加入以下代码到方法的结尾: + +````csharp +builder.Entity(b => +{ + b.ToTable(BookStoreConsts.DbTablePrefix + "Authors", + BookStoreConsts.DbSchema); + + b.ConfigureByConvention(); + + b.Property(x => x.Name) + .IsRequired() + .HasMaxLength(AuthorConsts.MaxNameLength); + + b.HasIndex(x => x.Name); +}); +```` + +这和前面的 `Book` 实体做的一样, 所以不再赘述. + +## 创建数据库迁移 + +配置启动解决方案为使用 [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/). 因为我们还没有修改数据库映射配置,所以需要创建一个新的迁移并对数据库应用变更. + +打开命令行终端, 切换当前目录为 `Acme.BookStore.EntityFrameworkCore` 项目目录, 输入以下命令: + +````bash +dotnet ef migrations add Added_Authors +```` + +这会在项目中添加一个迁移类: + +![bookstore-efcore-migration-authors](./images/bookstore-efcore-migration-authors.png) + +你可以在同一个命令行终端中使用以下命令对数据库应用更改: + +````bash +dotnet ef database update +```` + +> 如果你使用 Visual Studio, 可能希望在 *Package Manager Console (PMC)* 使用 `Add-Migration Added_Authors -c BookStoreMigrationsDbContext` 和 `Update-Database -c BookStoreMigrationsDbContext` 命令. 如果这样, 保证 {{if UI=="MVC"}}`Acme.BookStore.Web`{{else if UI=="BlazorServer"}}`Acme.BookStore.Blazor`{{else if UI=="Blazor" || UI=="NG"}}`Acme.BookStore.HttpApi.Host`{{end}} 是启动项目并且在PMC中 `Acme.BookStore.EntityFrameworkCore` 是 *默认项目* . + +{{else if DB=="Mongo"}} + +## DB Context + +打开 `Acme.BookStore.MongoDB` 项目 `MongoDb 文件夹`中的 `BookStoreMongoDbContext`, 在类中加入以下属性: + +````csharp +public IMongoCollection Authors => Collection(); +```` + +{{end}} + +## 实现 IAuthorRepository + +{{if DB=="EF"}} + +在 `Acme.BookStore.EntityFrameworkCore` 项目 (`Authors` 文件夹)中创建一个新类 `EfCoreAuthorRepository`, 粘贴以下代码: + +````csharp +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading.Tasks; +using Acme.BookStore.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Acme.BookStore.Authors +{ + public class EfCoreAuthorRepository + : EfCoreRepository, + IAuthorRepository + { + public EfCoreAuthorRepository( + IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + public async Task FindByNameAsync(string name) + { + var dbSet = await GetDbSetAsync(); + return await dbSet.FirstOrDefaultAsync(author => author.Name == name); + } + + public async Task> GetListAsync( + int skipCount, + int maxResultCount, + string sorting, + string filter = null) + { + var dbSet = await GetDbSetAsync(); + return await dbSet + .WhereIf( + !filter.IsNullOrWhiteSpace(), + author => author.Name.Contains(filter) + ) + .OrderBy(sorting) + .Skip(skipCount) + .Take(maxResultCount) + .ToListAsync(); + } + } +} +```` + +* 继承自 `EfCoreRepository`, 所以继承了标准repository的方法实现. +* `WhereIf` 是ABP 框架的快捷扩展方法. 它仅当第一个条件满足时, 执行 `Where` 查询. (根据名字查询, 仅当 filter 不为空). 你可以不使用这个方法, 但这些快捷方法可以提高效率. +* `sorting` 可以是一个字符串, 如 `Name`, `Name ASC` 或 `Name DESC`. 通过使用 [System.Linq.Dynamic.Core](https://www.nuget.org/packages/System.Linq.Dynamic.Core) NuGet 包是可能的. + +> 参阅 [EF Core 集成文档](../Entity-Framework-Core.md) 获得基于EF Core的repositories的更多信息. + +{{else if DB=="Mongo"}} + +在 `Acme.BookStore.MongoDB` 项目 (`Authors` 文件夹)中创建一个新类 `MongoDbAuthorRepository`, 粘贴以下代码: + +```csharp +using System; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Collections.Generic; +using System.Threading.Tasks; +using Acme.BookStore.MongoDB; +using MongoDB.Driver; +using MongoDB.Driver.Linq; +using Volo.Abp.Domain.Repositories.MongoDB; +using Volo.Abp.MongoDB; + +namespace Acme.BookStore.Authors +{ + public class MongoDbAuthorRepository + : MongoDbRepository, + IAuthorRepository + { + public MongoDbAuthorRepository( + IMongoDbContextProvider dbContextProvider + ) : base(dbContextProvider) + { + } + + public async Task FindByNameAsync(string name) + { + var queryable = await GetMongoQueryableAsync(); + return await queryable.FirstOrDefaultAsync(author => author.Name == name); + } + + public async Task> GetListAsync( + int skipCount, + int maxResultCount, + string sorting, + string filter = null) + { + var queryable = await GetMongoQueryableAsync(); + return await queryable + .WhereIf>( + !filter.IsNullOrWhiteSpace(), + author => author.Name.Contains(filter) + ) + .OrderBy(sorting) + .As>() + .Skip(skipCount) + .Take(maxResultCount) + .ToListAsync(); + } + } +} +``` + +* 继承自 `MongoDbRepository`, 所以继承了标准repository的方法实现. +* `WhereIf` 是ABP 框架的快捷扩展方法. 它仅当第一个条件满足时, 执行 `Where` 查询. (根据名字查询, 仅当 filter 不为空). 你可以不使用这个方法, 但这些快捷方法可以提高效率. +* `sorting` 可以是一个字符串, 如 `Name`, `Name ASC` 或 `Name DESC`. 通过使用 [System.Linq.Dynamic.Core](https://www.nuget.org/packages/System.Linq.Dynamic.Core) NuGet 包是可能的. + +> 参阅 [MongoDB 集成文档](../MongoDB.md) 获得基于MongoDB的repositories的更多信息. + +{{end}} + +## 下一章 + +查看本教程的[下一章](Part-8.md). diff --git a/docs/zh-Hans/Tutorials/images/bookstore-efcore-migration-authors.png b/docs/zh-Hans/Tutorials/images/bookstore-efcore-migration-authors.png new file mode 100644 index 0000000000000000000000000000000000000000..2cfb29f86f8d2d54e6cfbfe85f973525179ec51d GIT binary patch literal 7937 zcmaKxcQ~8<`}d=|P&BAfMWt%gDtenGRin0|HEM*|wQ383yJ%yys2Z)ks%nNxY*ne* zQZ!bK)?T4PkVN81@9*(^pX0cX-|zY3n#XZ{u5rH4*ZKaOSHgXhd#uctnE?O*tG=GL zIRL;QN8d-EKTBVSQ#|?T8-_shdv^gfLs!=62dCXNjWq!PWD3i%(;50P(-S?LKmdTP z`_IDA>-XLT01(X7*VcRx=77(m)(Ub$X92vJQJt-l6b%Ey(PD~~Y{wC_krWE9*$!Vgb56kGa&@0n4ghd<$_%I$zVAVt zi`Y@wRXrLz@&7JYHp2X^o(TYWRfG{X1Xh?M!04p&O6``3D{UBzgtcA~fUDs9KX57!La3nxy;?oD6*3?he}H0(T3 z;(!}CHAXDrSHIPlrM99qPDmTo{PqQYb7AG-;b#uRWYf5iLdSSFVh^~TkBKkOLUnmC zh=p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uH)1H0|TMr3;+NC literal 0 HcmV?d00001 From b4e4c92ffc42803585b3266ad07020cab83efd9c Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 30 Dec 2021 16:34:11 +0800 Subject: [PATCH 09/12] Add MakeProxyJsonFileEmbeddedStep --- .../ModuleProjectBuildPipelineBuilder.cs | 1 + .../Steps/MakeProxyJsonFileEmbeddedStep.cs | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/MakeProxyJsonFileEmbeddedStep.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleProjectBuildPipelineBuilder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleProjectBuildPipelineBuilder.cs index d4a74d9364..a5f5cb6d7d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleProjectBuildPipelineBuilder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleProjectBuildPipelineBuilder.cs @@ -12,6 +12,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building pipeline.Steps.Add(new FileEntryListReadStep()); pipeline.Steps.Add(new ProjectReferenceReplaceStep()); pipeline.Steps.Add(new ReplaceCommonPropsStep()); + pipeline.Steps.Add(new MakeProxyJsonFileEmbeddedStep()); pipeline.Steps.Add(new ReplaceConfigureAwaitPropsStep()); pipeline.Steps.Add(new UpdateNuGetConfigStep("/NuGet.Config")); pipeline.Steps.Add(new CreateProjectResultZipStep()); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/MakeProxyJsonFileEmbeddedStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/MakeProxyJsonFileEmbeddedStep.cs new file mode 100644 index 0000000000..f8de452172 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/MakeProxyJsonFileEmbeddedStep.cs @@ -0,0 +1,38 @@ +using System.Linq; +using System.Xml.Linq; +using Volo.Abp.Cli.Utils; + +namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps; + +public class MakeProxyJsonFileEmbeddedStep : ProjectBuildPipelineStep +{ + public override void Execute(ProjectBuildContext context) + { + foreach (var file in context.Files.Where(x => x.Name.EndsWith(".HttpApi.Client.csproj"))) + { + using (var stream = StreamHelper.GenerateStreamFromString(file.Content)) + { + var doc = XDocument.Load(stream); + + if (doc.Root == null) + { + continue; + } + + var itemGroupNode = + new XElement("ItemGroup", + new XElement("EmbeddedResource", + new XAttribute("Include", @"**\*generate-proxy.json") + ), + new XElement("Content", + new XAttribute("Remove", @"**\*generate-proxy.json") + ) + ); + + doc.Root.Add(itemGroupNode); + + file.SetContent(doc.ToString()); + } + } + } +} From 9b6d427dc74d30868a5d658179a35a713c4c6da3 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 31 Dec 2021 10:36:39 +0800 Subject: [PATCH 10/12] Fix the problem of background workers integration --- .../Hangfire/AbpBackgroundWorkersHangfireModule.cs | 2 +- .../Hangfire/HangfireBackgroundWorkerManager.cs | 14 +++++++++++--- .../QuartzPeriodicBackgroundWorkerAdapter.cs | 14 +++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs index 4efbdcffb7..c454c9f6e6 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire [DependsOn( typeof(AbpBackgroundWorkersModule), typeof(AbpHangfireModule))] - public class AbpBackgroundWorkerHangfireModule : AbpModule + public class AbpBackgroundWorkersHangfireModule : AbpModule { public override void OnPreApplicationInitialization(ApplicationInitializationContext context) { diff --git a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs index 272cc3cdcd..2a9cb33a10 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs @@ -42,9 +42,17 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase) { - var timer = (AbpAsyncTimer) worker.GetType() + var timer = worker.GetType() .GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); - period = timer?.Period; + + if (worker is AsyncPeriodicBackgroundWorkerBase) + { + period = ((AbpAsyncTimer)timer)?.Period; + } + else + { + period = ((AbpTimer)timer)?.Period; + } } else { @@ -82,7 +90,7 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire } else { - cron = $"0 0 */{time.TotalDays} * *"; + throw new AbpException($"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker"); } return cron; diff --git a/framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzPeriodicBackgroundWorkerAdapter.cs b/framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzPeriodicBackgroundWorkerAdapter.cs index aa99434ed5..16286d3153 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzPeriodicBackgroundWorkerAdapter.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzPeriodicBackgroundWorkerAdapter.cs @@ -28,15 +28,23 @@ namespace Volo.Abp.BackgroundWorkers.Quartz int? period; var workerType = worker.GetType(); - if (worker is AsyncPeriodicBackgroundWorkerBase || worker is PeriodicBackgroundWorkerBase) + if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase) { if (typeof(TWorker) != worker.GetType()) { throw new ArgumentException($"{nameof(worker)} type is different from the generic type"); } - var timer = (AbpAsyncTimer) worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); - period = timer?.Period; + var timer = worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); + + if (worker is AsyncPeriodicBackgroundWorkerBase) + { + period = ((AbpAsyncTimer)timer)?.Period; + } + else + { + period = ((AbpTimer)timer)?.Period; + } } else { From 6cd448baa7b3aeb2928fd590e82258c7a1d8e074 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 31 Dec 2021 11:28:25 +0800 Subject: [PATCH 11/12] Update PreConfigureActionList.cs --- .../Volo/Abp/Options/PreConfigureActionList.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs index 4792cfc668..bf8bb90f55 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Options/PreConfigureActionList.cs @@ -11,12 +11,12 @@ public class PreConfigureActionList : List> { action(options); } + } - public TOptions Configure() - { - var options = Activator.CreateInstance(); - Configure(options); - return options; - } + public TOptions Configure() + { + var options = Activator.CreateInstance(); + Configure(options); + return options; } } From e914ff859f3e9cbb0f630d376f7d7da27cd34fa6 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 31 Dec 2021 12:18:28 +0800 Subject: [PATCH 12/12] Update HangfireBackgroundWorkerManager.cs --- .../Hangfire/HangfireBackgroundWorkerManager.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs index e7c92f1296..33e0ebde4c 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs @@ -21,7 +21,7 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle return Task.CompletedTask; } - public void Add(IBackgroundWorker worker) + public Task AddAsync(IBackgroundWorker worker) { if (worker is IHangfireBackgroundWorker hangfireBackgroundWorker) { @@ -56,12 +56,12 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle } else { - return; + return Task.CompletedTask; } if (period == null) { - return; + return Task.CompletedTask; } var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(worker.GetType()); @@ -69,6 +69,8 @@ public class HangfireBackgroundWorkerManager : IBackgroundWorkerManager, ISingle RecurringJob.AddOrUpdate(() => workerAdapter.DoWorkAsync(), GetCron(period.Value)); } + + return Task.CompletedTask; } protected virtual string GetCron(int period)