From af6b013395a7185c12dcac41b70ecc970e424567 Mon Sep 17 00:00:00 2001 From: Salih Date: Thu, 14 Jul 2022 10:52:13 +0300 Subject: [PATCH 01/12] Update en.json Add localizations for Microservice E-Book --- .../Www/Localization/Resources/en.json | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json index 41eda60de6..d1d4636eab 100644 --- a/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json @@ -372,6 +372,19 @@ "MasteringAbpFramework_Book_What_You_Will_Learn_8": "Write unit, integration, and UI tests using ABP Framework.", "MasteringAbpFramework_Book_WhoIsThisBookFor": "Who's this book for", "MasteringAbpFramework_Book_WhoIsThisBookFor_Description": "This book is for web developers who want to learn software architectures and best practices for building\n maintainable web-based solutions using Microsoft technologies and ABP Framework. Basic knowledge of C#\n and ASP.NET Core is necessary to get started with this book.", - "ComputersAndTechnology": "Computers & Technology" + "ComputersAndTechnology": "Computers & Technology", + "BuildingMicroserviceSolutions":"Building Microservice Solutions", + "MicroserviceBookPracticalGuide":"This book is a reference guide for developing and managing microservice-based applications using the ABP Framework. It references the .*NET Microservice Sample Rerefence Application*: eShopOnContainers and discusses the architectural design and implementation approaches using the ABP Framework. Moreover, you will learn the working implementation of an e-shop process like adding products, completing the purchase using PayPal, updating the basket cart item in real-time, shipping a purchased product, and more. Written by the main contributors of the ABP Framework, this book will help you understand how the ABP modularity is used like lego pieces to become a running distributed system. It will discuss the decisions to create a microservice environment and how to develop an application rapidly.By the end of this book, you'll learn how ABP approaches the common microservice complexities such as authorization, distributed transactions, inter-microservice communications, deployment, etc. ", + "IntroducingMicroservice":"Introducing Microservice", + "RunningTheSolution":"Running the Solution", + "UnderstandingTheAuthenticationSystem":"Understanding the Authentication System", + "ExploringTheApplications":"Exploring the Applications", + "UnderstandingTheAPIGateways":"Understanding the API Gateways", + "DevelopingTheMicroservices":"Developing the Microservices", + "UnderstandingTheInfrastructure":"Understanding the Infrastructure", + "DiggingInTheUseCases":"Digging in the Use Cases", + "DeployingTheSolution":"Deploying the Solution", + "Authors":"Authors", + "MicroserviceEBook":"Microservice E-Book" } } From f87002eee12b580c6671c8f40f4c8d16423f0842 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 21 Jul 2022 12:14:05 +0800 Subject: [PATCH 02/12] Remove `IHybridServiceScopeFactory`. Resolve #12246 --- .../PageToolbars/PageToolbarManager.cs | 5 +- .../PageToolbars/PageToolbarManager.cs | 5 +- .../HttpContextServiceScopeFactory.cs | 52 -------------- .../Abp/Cli/Commands/GenerateProxyCommand.cs | 3 +- .../Volo/Abp/Cli/Commands/ProxyCommandBase.cs | 5 +- .../Abp/Cli/Commands/RemoveProxyCommand.cs | 3 +- .../DefaultServiceScopeFactory.cs | 22 ------ .../IHybridServiceScopeFactory.cs | 8 --- .../Volo/Abp/Ui/Navigation/MenuManager.cs | 5 +- .../HybridServiceScopeFactory_Tests.cs | 71 ------------------- .../Abp/FeatureManagement/FeatureManager.cs | 2 +- .../IdentityServer/AbpCorsPolicyService.cs | 4 +- .../AbpWildcardSubdomainCorsPolicyService.cs | 3 +- .../AbpResourceOwnerPasswordValidator.cs | 4 +- .../Controllers/TokenController.Password.cs | 2 +- .../Abp/SettingManagement/SettingManager.cs | 2 +- 16 files changed, 25 insertions(+), 171 deletions(-) delete mode 100644 framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/DependencyInjection/HttpContextServiceScopeFactory.cs delete mode 100644 framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultServiceScopeFactory.cs delete mode 100644 framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IHybridServiceScopeFactory.cs delete mode 100644 framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/HybridServiceScopeFactory_Tests.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs index 05531096d4..00f7f5da23 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs @@ -3,16 +3,17 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars; public class PageToolbarManager : IPageToolbarManager, ITransientDependency { - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } public PageToolbarManager( - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) { ServiceScopeFactory = serviceScopeFactory; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs index b795c62c39..ec27b8087c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -10,11 +11,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.PageToolbars; public class PageToolbarManager : IPageToolbarManager, ITransientDependency { protected AbpPageToolbarOptions Options { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } public PageToolbarManager( IOptions options, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) { Options = options.Value; ServiceScopeFactory = serviceScopeFactory; diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/DependencyInjection/HttpContextServiceScopeFactory.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/DependencyInjection/HttpContextServiceScopeFactory.cs deleted file mode 100644 index a7f00f7451..0000000000 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/DependencyInjection/HttpContextServiceScopeFactory.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.DependencyInjection; - -namespace Volo.Abp.AspNetCore.DependencyInjection; - -[ExposeServices( - typeof(IHybridServiceScopeFactory), - typeof(HttpContextServiceScopeFactory) - )] -[Dependency(ReplaceServices = true)] -public class HttpContextServiceScopeFactory : IHybridServiceScopeFactory, ITransientDependency -{ - protected IHttpContextAccessor HttpContextAccessor { get; } - - protected IServiceScopeFactory ServiceScopeFactory { get; } - - public HttpContextServiceScopeFactory( - IHttpContextAccessor httpContextAccessor, - IServiceScopeFactory serviceScopeFactory) - { - HttpContextAccessor = httpContextAccessor; - ServiceScopeFactory = serviceScopeFactory; - } - - public virtual IServiceScope CreateScope() - { - var httpContext = HttpContextAccessor.HttpContext; - if (httpContext == null) - { - return ServiceScopeFactory.CreateScope(); - } - - return new NonDisposedHttpContextServiceScope(httpContext.RequestServices); - } - - protected class NonDisposedHttpContextServiceScope : IServiceScope - { - public IServiceProvider ServiceProvider { get; } - - public NonDisposedHttpContextServiceScope(IServiceProvider serviceProvider) - { - ServiceProvider = serviceProvider; - } - - public void Dispose() - { - - } - } -} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs index bf8e2e3028..7874fddb86 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs @@ -1,4 +1,5 @@ using System.Text; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Cli.ServiceProxying; using Volo.Abp.DependencyInjection; @@ -13,7 +14,7 @@ public class GenerateProxyCommand : ProxyCommandBase public GenerateProxyCommand( IOptions serviceProxyOptions, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) : base(serviceProxyOptions, serviceScopeFactory) { } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs index 22311bb986..67c61b2a28 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -19,11 +20,11 @@ public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependenc protected AbpCliServiceProxyOptions ServiceProxyOptions { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } public ProxyCommandBase( IOptions serviceProxyOptions, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) { ServiceScopeFactory = serviceScopeFactory; ServiceProxyOptions = serviceProxyOptions.Value; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs index d89c19c892..3372584f1a 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs @@ -1,4 +1,5 @@ using System.Text; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Cli.ServiceProxying; using Volo.Abp.DependencyInjection; @@ -13,7 +14,7 @@ public class RemoveProxyCommand : ProxyCommandBase public RemoveProxyCommand( IOptions serviceProxyOptions, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) : base(serviceProxyOptions, serviceScopeFactory) { } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultServiceScopeFactory.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultServiceScopeFactory.cs deleted file mode 100644 index befcf7951e..0000000000 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultServiceScopeFactory.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace Volo.Abp.DependencyInjection; - -[ExposeServices( - typeof(IHybridServiceScopeFactory), - typeof(DefaultServiceScopeFactory) - )] -public class DefaultServiceScopeFactory : IHybridServiceScopeFactory, ITransientDependency -{ - protected IServiceScopeFactory Factory { get; } - - public DefaultServiceScopeFactory(IServiceScopeFactory factory) - { - Factory = factory; - } - - public IServiceScope CreateScope() - { - return Factory.CreateScope(); - } -} diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IHybridServiceScopeFactory.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IHybridServiceScopeFactory.cs deleted file mode 100644 index 62c3707352..0000000000 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IHybridServiceScopeFactory.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace Volo.Abp.DependencyInjection; - -public interface IHybridServiceScopeFactory : IServiceScopeFactory -{ - -} diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs index d325708175..aa933c6e09 100644 --- a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Authorization.Permissions; using Volo.Abp.DependencyInjection; @@ -13,11 +14,11 @@ namespace Volo.Abp.UI.Navigation; public class MenuManager : IMenuManager, ITransientDependency { protected AbpNavigationOptions Options { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } protected ISimpleStateCheckerManager SimpleStateCheckerManager { get; } public MenuManager( IOptions options, - IHybridServiceScopeFactory serviceScopeFactory, + IServiceScopeFactory serviceScopeFactory, ISimpleStateCheckerManager simpleStateCheckerManager) { Options = options.Value; diff --git a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/HybridServiceScopeFactory_Tests.cs b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/HybridServiceScopeFactory_Tests.cs deleted file mode 100644 index 6a3f059ba8..0000000000 --- a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/HybridServiceScopeFactory_Tests.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using Shouldly; -using Volo.Abp.Modularity; -using Xunit; - -namespace Volo.Abp.DependencyInjection; - -public class HybridServiceScopeFactory_Tests -{ - [Fact] - public async Task Should_Use_Default_ServiceScopeFactory_By_Default_Async() - { - using (var application = await AbpApplicationFactory.CreateAsync()) - { - application.Services.AddType(typeof(MyServiceAsync)); - - await application.InitializeAsync(); - - var serviceScopeFactory = application.ServiceProvider.GetRequiredService(); - - using (var scope = serviceScopeFactory.CreateScope()) - { - scope.ServiceProvider.GetRequiredService(); - } - - MyServiceAsync.DisposeCount.ShouldBe(1); - } - } - - [Fact] - public void Should_Use_Default_ServiceScopeFactory_By_Default() - { - using (var application = AbpApplicationFactory.Create()) - { - application.Services.AddType(typeof(MyService)); - - application.Initialize(); - - var serviceScopeFactory = application.ServiceProvider.GetRequiredService(); - - using (var scope = serviceScopeFactory.CreateScope()) - { - scope.ServiceProvider.GetRequiredService(); - } - - MyService.DisposeCount.ShouldBe(1); - } - } - - private class MyServiceAsync : ITransientDependency, IDisposable - { - public static int DisposeCount { get; private set; } - - public void Dispose() - { - ++DisposeCount; - } - } - - private class MyService : ITransientDependency, IDisposable - { - public static int DisposeCount { get; private set; } - - public void Dispose() - { - ++DisposeCount; - } - } -} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs index 06c293219b..36800a9a33 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs @@ -29,7 +29,7 @@ public class FeatureManager : IFeatureManager, ISingletonDependency StringLocalizerFactory = stringLocalizerFactory; Options = options.Value; - //TODO: Instead, use IHybridServiceScopeFactory and create a scope..? + //TODO: Instead, use IServiceScopeFactory and create a scope..? _lazyProviders = new Lazy>( () => Options diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs index ac6c9d9edf..bc711254f1 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs @@ -17,13 +17,13 @@ namespace Volo.Abp.IdentityServer; public class AbpCorsPolicyService : ICorsPolicyService { public ILogger Logger { get; set; } - protected IHybridServiceScopeFactory HybridServiceScopeFactory { get; } + protected IServiceScopeFactory HybridServiceScopeFactory { get; } protected IDistributedCache Cache { get; } protected IdentityServerOptions Options { get; } public AbpCorsPolicyService( IDistributedCache cache, - IHybridServiceScopeFactory hybridServiceScopeFactory, + IServiceScopeFactory hybridServiceScopeFactory, IOptions options) { Cache = cache; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs index 82658ceccd..32d2d1eb73 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using IdentityServer4.Configuration; using Microsoft.Extensions.Options; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Text.Formatting; @@ -13,7 +14,7 @@ public class AbpWildcardSubdomainCorsPolicyService : AbpCorsPolicyService { public AbpWildcardSubdomainCorsPolicyService( IDistributedCache cache, - IHybridServiceScopeFactory hybridServiceScopeFactory, + IServiceScopeFactory hybridServiceScopeFactory, IOptions options) : base(cache, hybridServiceScopeFactory, options) { diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs index 77181a8b8b..cf69fda91a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs @@ -32,7 +32,7 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } protected ILogger> Logger { get; } protected IStringLocalizer Localizer { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } protected AbpIdentityOptions AbpIdentityOptions { get; } protected IOptions IdentityOptions { get; } @@ -43,7 +43,7 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator ILogger> logger, IStringLocalizer localizer, IOptions abpIdentityOptions, - IHybridServiceScopeFactory serviceScopeFactory, + IServiceScopeFactory serviceScopeFactory, IOptions identityOptions) { UserManager = userManager; diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs index 49d415c927..1484ea4b52 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs @@ -22,7 +22,7 @@ namespace Volo.Abp.OpenIddict.Controllers; public partial class TokenController { - protected IHybridServiceScopeFactory ServiceScopeFactory => LazyServiceProvider.LazyGetRequiredService(); + protected IServiceScopeFactory ServiceScopeFactory => LazyServiceProvider.LazyGetRequiredService(); protected ITenantConfigurationProvider TenantConfigurationProvider=> LazyServiceProvider.LazyGetRequiredService(); protected IOptions AbpIdentityOptions => LazyServiceProvider.LazyGetRequiredService>(); protected IOptions IdentityOptions => LazyServiceProvider.LazyGetRequiredService>(); diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs index 14629b988e..570c99925b 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs @@ -27,7 +27,7 @@ public class SettingManager : ISettingManager, ISingletonDependency SettingEncryptionService = settingEncryptionService; Options = options.Value; - //TODO: Instead, use IHybridServiceScopeFactory and create a scope..? + //TODO: Instead, use IServiceScopeFactory and create a scope..? _lazyProviders = new Lazy>( () => Options From fdfc39d1cf298b8e86cd275002c276749a257657 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 29 Jul 2022 01:49:57 +0300 Subject: [PATCH 03/12] Removed unused usings --- .../Pages/Index.cshtml.cs | 1 - .../MyProjectNameBlazorModule.cs | 1 - .../MyProjectNameBlazorModule.cs | 2 -- .../MyProjectNameHttpApiHostModule.cs | 3 --- .../MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs | 1 - 5 files changed, 8 deletions(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.AuthServer/Pages/Index.cshtml.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.AuthServer/Pages/Index.cshtml.cs index 8e31fb91f1..f5fef94c78 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.AuthServer/Pages/Index.cshtml.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.AuthServer/Pages/Index.cshtml.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Globalization; -using System.Threading; using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.Localization; diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.Tiered/MyProjectNameBlazorModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.Tiered/MyProjectNameBlazorModule.cs index f3a2e1da9f..b8c91610b9 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.Tiered/MyProjectNameBlazorModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.Tiered/MyProjectNameBlazorModule.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Net.Http; using Blazorise.Bootstrap5; using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Builder; diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs index 338ae879b8..84abc220c8 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs @@ -2,7 +2,6 @@ using System.Net.Http; using Blazorise.Bootstrap5; using Blazorise.Icons.FontAwesome; -using IdentityModel; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -16,7 +15,6 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; using Volo.Abp.UI.Navigation; using Volo.Abp.Identity.Blazor.WebAssembly; -using Volo.Abp.Security.Claims; using Volo.Abp.SettingManagement.Blazor.WebAssembly; using Volo.Abp.TenantManagement.Blazor.WebAssembly; diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs index 4edcc7a73f..dc32d493b1 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; @@ -11,7 +10,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.IdentityModel.Tokens; using MyCompanyName.MyProjectName.EntityFrameworkCore; using MyCompanyName.MyProjectName.MultiTenancy; using StackExchange.Redis; @@ -19,7 +17,6 @@ using Microsoft.OpenApi.Models; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; -using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Autofac; using Volo.Abp.Caching; diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs index bc47df706c..7ee120f135 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Extensions.DependencyInjection; From 6436db9ec797ea5be0a9baba4306c5f99e1e7d24 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 29 Jul 2022 09:59:51 +0800 Subject: [PATCH 04/12] Update environment.prod.ts --- .../app/angular/src/environments/environment.prod.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/openiddict/app/angular/src/environments/environment.prod.ts b/modules/openiddict/app/angular/src/environments/environment.prod.ts index ae8f02f96b..c0fcaf39a2 100644 --- a/modules/openiddict/app/angular/src/environments/environment.prod.ts +++ b/modules/openiddict/app/angular/src/environments/environment.prod.ts @@ -10,16 +10,17 @@ export const environment = { logoUrl: '', }, oAuthConfig: { - issuer: 'https://localhost:44333', + issuer: 'https://localhost:44301/', redirectUri: baseUrl, - clientId: 'Angular_App', + clientId: 'AbpApp', + dummyClientSecret: '1q2w3e*', responseType: 'code', - scope: 'offline_access Angular', + scope: 'offline_access AbpAPI', requireHttps: true }, apis: { default: { - url: 'https://localhost:44333', + url: 'https://localhost:44301', rootNamespace: 'OpenIddict.Demo.Client.Angular', }, }, From 30bd5caf2eb7c82866efe745421ab40e65df94eb Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:22:02 +0800 Subject: [PATCH 05/12] Remove EntityCreatingEventData, EntityUpdatingEventData, EntityDeletingEventData and EntityChangingEventData --- .../Events/EntityChangeEventHelper.cs | 227 ------------------ .../Events/EntityChangingEventData.cs | 23 -- .../Events/EntityCreatingEventData.cs | 22 -- .../Events/EntityDeletingEventData.cs | 22 -- .../Events/EntityUpdatingEventData.cs | 22 -- .../Testing/EntityChangeEvents_Tests.cs | 19 +- 6 files changed, 1 insertion(+), 334 deletions(-) delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs deleted file mode 100644 index 8f9be2318f..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs +++ /dev/null @@ -1,227 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.Extensions.Options; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Domain.Entities.Events.Distributed; -using Volo.Abp.DynamicProxy; -using Volo.Abp.EventBus; -using Volo.Abp.EventBus.Distributed; -using Volo.Abp.EventBus.Local; -using Volo.Abp.Uow; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// Used to trigger entity change events. -/// -public class EntityChangeEventHelper : IEntityChangeEventHelper, ITransientDependency -{ - private const string UnitOfWorkEventRecordEntityPropName = "_Abp_Entity"; - - public ILogger Logger { get; set; } - public ILocalEventBus LocalEventBus { get; set; } - public IDistributedEventBus DistributedEventBus { get; set; } - - protected IUnitOfWorkManager UnitOfWorkManager { get; } - protected IEntityToEtoMapper EntityToEtoMapper { get; } - protected AbpDistributedEntityEventOptions DistributedEntityEventOptions { get; } - - public EntityChangeEventHelper( - IUnitOfWorkManager unitOfWorkManager, - IEntityToEtoMapper entityToEtoMapper, - IOptions distributedEntityEventOptions) - { - UnitOfWorkManager = unitOfWorkManager; - EntityToEtoMapper = entityToEtoMapper; - DistributedEntityEventOptions = distributedEntityEventOptions.Value; - - LocalEventBus = NullLocalEventBus.Instance; - DistributedEventBus = NullDistributedEventBus.Instance; - Logger = NullLogger.Instance; - } - - public virtual void PublishEntityCreatingEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, -#pragma warning disable 618 - typeof(EntityCreatingEventData<>), -#pragma warning restore 618 - entity, - entity - ); - } - - public virtual void PublishEntityCreatedEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, - typeof(EntityCreatedEventData<>), - entity, - entity - ); - - if (ShouldPublishDistributedEventForEntity(entity)) - { - var eto = EntityToEtoMapper.Map(entity); - if (eto != null) - { - TriggerEventWithEntity( - DistributedEventBus, - typeof(EntityCreatedEto<>), - eto, - entity - ); - } - } - } - - private bool ShouldPublishDistributedEventForEntity(object entity) - { - return DistributedEntityEventOptions - .AutoEventSelectors - .IsMatch( - ProxyHelper - .UnProxy(entity) - .GetType() - ); - } - - public virtual void PublishEntityUpdatingEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, -#pragma warning disable 618 - typeof(EntityUpdatingEventData<>), -#pragma warning restore 618 - entity, - entity - ); - } - - public virtual void PublishEntityUpdatedEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, - typeof(EntityUpdatedEventData<>), - entity, - entity - ); - - if (ShouldPublishDistributedEventForEntity(entity)) - { - var eto = EntityToEtoMapper.Map(entity); - if (eto != null) - { - TriggerEventWithEntity( - DistributedEventBus, - typeof(EntityUpdatedEto<>), - eto, - entity - ); - } - } - } - - public virtual void PublishEntityDeletingEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, -#pragma warning disable 618 - typeof(EntityDeletingEventData<>), -#pragma warning restore 618 - entity, - entity - ); - } - - public virtual void PublishEntityDeletedEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, - typeof(EntityDeletedEventData<>), - entity, - entity - ); - - if (ShouldPublishDistributedEventForEntity(entity)) - { - var eto = EntityToEtoMapper.Map(entity); - if (eto != null) - { - TriggerEventWithEntity( - DistributedEventBus, - typeof(EntityDeletedEto<>), - eto, - entity - ); - } - } - } - - protected virtual void TriggerEventWithEntity( - IEventBus eventPublisher, - Type genericEventType, - object entityOrEto, - object originalEntity) - { - var entityType = ProxyHelper.UnProxy(entityOrEto).GetType(); - var eventType = genericEventType.MakeGenericType(entityType); - var eventData = Activator.CreateInstance(eventType, entityOrEto); - var currentUow = UnitOfWorkManager.Current; - - if (currentUow == null) - { - Logger.LogWarning("UnitOfWorkManager.Current is null! Can not publish the event."); - return; - } - - var eventRecord = new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext()) - { - Properties = - { - { UnitOfWorkEventRecordEntityPropName, originalEntity }, - } - }; - - /* We are trying to eliminate same events for the same entity. - * In this way, for example, we don't trigger update event for an entity multiple times - * even if it is updated multiple times in the current UOW. - */ - - if (eventPublisher == DistributedEventBus) - { - currentUow.AddOrReplaceDistributedEvent( - eventRecord, - otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) - ); - } - else - { - currentUow.AddOrReplaceLocalEvent( - eventRecord, - otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) - ); - } - } - - public bool IsSameEntityEventRecord(UnitOfWorkEventRecord record1, UnitOfWorkEventRecord record2) - { - if (record1.EventType != record2.EventType) - { - return false; - } - - var record1OriginalEntity = record1.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; - var record2OriginalEntity = record2.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; - - if (record1OriginalEntity == null || record2OriginalEntity == null) - { - return false; - } - - return EntityHelper.EntityEquals(record1OriginalEntity, record2OriginalEntity); - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs deleted file mode 100644 index ae24163966..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// Used to pass data for an event when an entity () is being changed (creating, updating or deleting). -/// See , and classes. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityChangedEventData. Please use EntityChangedEventData instead.")] -public class EntityChangingEventData : EntityEventData -{ - /// - /// Constructor. - /// - /// Changing entity in this event - public EntityChangingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs deleted file mode 100644 index 914c8ca7c7..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// This type of event is used to notify just before creation of an Entity. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityCreatedEventData. Please use EntityCreatedEventData instead.")] -public class EntityCreatingEventData : EntityChangingEventData -{ - /// - /// Constructor. - /// - /// The entity which is being created - public EntityCreatingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs deleted file mode 100644 index af0d1218f7..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// This type of event is used to notify just before deletion of an Entity. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityDeletedEventData. Please use EntityDeletedEventData instead.")] -public class EntityDeletingEventData : EntityChangingEventData -{ - /// - /// Constructor. - /// - /// The entity which is being deleted - public EntityDeletingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs deleted file mode 100644 index 703304fefb..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// This type of event is used to notify just before update of an Entity. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityUpdatedEventData. Please use EntityUpdatedEventData instead.")] -public class EntityUpdatingEventData : EntityChangingEventData -{ - /// - /// Constructor. - /// - /// The entity which is being updated - public EntityUpdatingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs index a94c722faf..c6ffa48d37 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs @@ -38,23 +38,6 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase using (var uow = GetRequiredService().Begin()) { -#pragma warning disable 618 - LocalEventBus.Subscribe>(data => -#pragma warning restore 618 - { - creatingEventTriggered.ShouldBeFalse(); - createdEventTriggered.ShouldBeFalse(); - - creatingEventTriggered = true; - - data.Entity.Name.ShouldBe(personName); - - /* Want to change age from 15 to 18 */ - data.Entity.Age.ShouldBe(15); - data.Entity.Age = 18; - return Task.CompletedTask; - }); - LocalEventBus.Subscribe>(data => { creatingEventTriggered.ShouldBeTrue(); @@ -62,7 +45,7 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase createdEventTriggered = true; - data.Entity.Age.ShouldBe(18); + data.Entity.Age.ShouldBe(15); data.Entity.Name.ShouldBe(personName); return Task.CompletedTask; From 300cde89c28e3759e01bf713b3c3647b4843a497 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:27:39 +0800 Subject: [PATCH 06/12] Update EntityChangeEventHelper.cs --- .../Events/EntityChangeEventHelper.cs | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs new file mode 100644 index 0000000000..20556f16ff --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs @@ -0,0 +1,191 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Entities.Events.Distributed; +using Volo.Abp.DynamicProxy; +using Volo.Abp.EventBus; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.EventBus.Local; +using Volo.Abp.Uow; + +namespace Volo.Abp.Domain.Entities.Events; + +/// +/// Used to trigger entity change events. +/// +public class EntityChangeEventHelper : IEntityChangeEventHelper, ITransientDependency +{ + private const string UnitOfWorkEventRecordEntityPropName = "_Abp_Entity"; + + public ILogger Logger { get; set; } + public ILocalEventBus LocalEventBus { get; set; } + public IDistributedEventBus DistributedEventBus { get; set; } + + protected IUnitOfWorkManager UnitOfWorkManager { get; } + protected IEntityToEtoMapper EntityToEtoMapper { get; } + protected AbpDistributedEntityEventOptions DistributedEntityEventOptions { get; } + + public EntityChangeEventHelper( + IUnitOfWorkManager unitOfWorkManager, + IEntityToEtoMapper entityToEtoMapper, + IOptions distributedEntityEventOptions) + { + UnitOfWorkManager = unitOfWorkManager; + EntityToEtoMapper = entityToEtoMapper; + DistributedEntityEventOptions = distributedEntityEventOptions.Value; + + LocalEventBus = NullLocalEventBus.Instance; + DistributedEventBus = NullDistributedEventBus.Instance; + Logger = NullLogger.Instance; + } + + public virtual void PublishEntityCreatedEvent(object entity) + { + TriggerEventWithEntity( + LocalEventBus, + typeof(EntityCreatedEventData<>), + entity, + entity + ); + + if (ShouldPublishDistributedEventForEntity(entity)) + { + var eto = EntityToEtoMapper.Map(entity); + if (eto != null) + { + TriggerEventWithEntity( + DistributedEventBus, + typeof(EntityCreatedEto<>), + eto, + entity + ); + } + } + } + + private bool ShouldPublishDistributedEventForEntity(object entity) + { + return DistributedEntityEventOptions + .AutoEventSelectors + .IsMatch( + ProxyHelper + .UnProxy(entity) + .GetType() + ); + } + + public virtual void PublishEntityUpdatedEvent(object entity) + { + TriggerEventWithEntity( + LocalEventBus, + typeof(EntityUpdatedEventData<>), + entity, + entity + ); + + if (ShouldPublishDistributedEventForEntity(entity)) + { + var eto = EntityToEtoMapper.Map(entity); + if (eto != null) + { + TriggerEventWithEntity( + DistributedEventBus, + typeof(EntityUpdatedEto<>), + eto, + entity + ); + } + } + } + + public virtual void PublishEntityDeletedEvent(object entity) + { + TriggerEventWithEntity( + LocalEventBus, + typeof(EntityDeletedEventData<>), + entity, + entity + ); + + if (ShouldPublishDistributedEventForEntity(entity)) + { + var eto = EntityToEtoMapper.Map(entity); + if (eto != null) + { + TriggerEventWithEntity( + DistributedEventBus, + typeof(EntityDeletedEto<>), + eto, + entity + ); + } + } + } + + protected virtual void TriggerEventWithEntity( + IEventBus eventPublisher, + Type genericEventType, + object entityOrEto, + object originalEntity) + { + var entityType = ProxyHelper.UnProxy(entityOrEto).GetType(); + var eventType = genericEventType.MakeGenericType(entityType); + var eventData = Activator.CreateInstance(eventType, entityOrEto); + var currentUow = UnitOfWorkManager.Current; + + if (currentUow == null) + { + Logger.LogWarning("UnitOfWorkManager.Current is null! Can not publish the event."); + return; + } + + var eventRecord = new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext()) + { + Properties = + { + { UnitOfWorkEventRecordEntityPropName, originalEntity }, + } + }; + + /* We are trying to eliminate same events for the same entity. + * In this way, for example, we don't trigger update event for an entity multiple times + * even if it is updated multiple times in the current UOW. + */ + + if (eventPublisher == DistributedEventBus) + { + currentUow.AddOrReplaceDistributedEvent( + eventRecord, + otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) + ); + } + else + { + currentUow.AddOrReplaceLocalEvent( + eventRecord, + otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) + ); + } + } + + public bool IsSameEntityEventRecord(UnitOfWorkEventRecord record1, UnitOfWorkEventRecord record2) + { + if (record1.EventType != record2.EventType) + { + return false; + } + + var record1OriginalEntity = record1.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; + var record2OriginalEntity = record2.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; + + if (record1OriginalEntity == null || record2OriginalEntity == null) + { + return false; + } + + return EntityHelper.EntityEquals(record1OriginalEntity, record2OriginalEntity); + } +} From f9e903b43b3adf437f9607f5e4350e0dd5639370 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:44:29 +0800 Subject: [PATCH 07/12] Improve --- .../Entities/Events/IEntityChangeEventHelper.cs | 3 --- .../Entities/Events/NullEntityChangeEventHelper.cs | 12 ------------ .../Volo/Abp/EntityFrameworkCore/AbpDbContext.cs | 4 ---- .../Repositories/MemoryDb/MemoryDbRepository.cs | 3 --- .../Domain/Repositories/MongoDB/MongoDbRepository.cs | 3 --- 5 files changed, 25 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs index db580a0682..aa63c7e3c9 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs @@ -5,12 +5,9 @@ namespace Volo.Abp.Domain.Entities.Events; /// public interface IEntityChangeEventHelper { - void PublishEntityCreatingEvent(object entity); void PublishEntityCreatedEvent(object entity); - void PublishEntityUpdatingEvent(object entity); void PublishEntityUpdatedEvent(object entity); - void PublishEntityDeletingEvent(object entity); void PublishEntityDeletedEvent(object entity); } diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs index d428f84d6f..4d849f2f27 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs @@ -14,26 +14,14 @@ public class NullEntityChangeEventHelper : IEntityChangeEventHelper { } - public void PublishEntityCreatingEvent(object entity) - { - } - public void PublishEntityCreatedEvent(object entity) { } - public void PublishEntityUpdatingEvent(object entity) - { - } - public void PublishEntityUpdatedEvent(object entity) { } - public void PublishEntityDeletingEvent(object entity) - { - } - public void PublishEntityDeletedEvent(object entity) { } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 3a8a24bf62..fd998510af 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -292,7 +292,6 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, { case EntityState.Added: ApplyAbpConceptsForAddedEntity(entry); - EntityChangeEventHelper.PublishEntityCreatingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityCreatedEvent(entry.Entity); break; case EntityState.Modified: @@ -301,12 +300,10 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, { if (entry.Entity is ISoftDelete && entry.Entity.As().IsDeleted) { - EntityChangeEventHelper.PublishEntityDeletingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityDeletedEvent(entry.Entity); } else { - EntityChangeEventHelper.PublishEntityUpdatingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityUpdatedEvent(entry.Entity); } } @@ -314,7 +311,6 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, break; case EntityState.Deleted: ApplyAbpConceptsForDeletedEntity(entry); - EntityChangeEventHelper.PublishEntityDeletingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityDeletedEvent(entry.Entity); break; } diff --git a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index 2bcfc1bad7..61bb9745e2 100644 --- a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -159,19 +159,16 @@ public class MemoryDbRepository : RepositoryBase private void TriggerEntityCreateEvents(TEntity entity) { - EntityChangeEventHelper.PublishEntityCreatingEvent(entity); EntityChangeEventHelper.PublishEntityCreatedEvent(entity); } protected virtual void TriggerEntityUpdateEvents(TEntity entity) { - EntityChangeEventHelper.PublishEntityUpdatingEvent(entity); EntityChangeEventHelper.PublishEntityUpdatedEvent(entity); } @@ -616,7 +614,6 @@ public class MongoDbRepository protected virtual void TriggerEntityDeleteEvents(TEntity entity) { - EntityChangeEventHelper.PublishEntityDeletingEvent(entity); EntityChangeEventHelper.PublishEntityDeletedEvent(entity); } From 03e7412e9aece512dd1da0665fe2c15fa0a3ce7a Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:46:57 +0800 Subject: [PATCH 08/12] Update EntityChangeEvents_Tests.cs --- .../Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs index c6ffa48d37..12b3fa01c0 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs @@ -32,7 +32,6 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase { var personName = Guid.NewGuid().ToString("N"); - var creatingEventTriggered = false; var createdEventTriggered = false; var createdEtoTriggered = false; @@ -40,7 +39,6 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase { LocalEventBus.Subscribe>(data => { - creatingEventTriggered.ShouldBeTrue(); createdEventTriggered.ShouldBeFalse(); createdEventTriggered = true; @@ -64,8 +62,7 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase await uow.CompleteAsync(); } - - creatingEventTriggered.ShouldBeTrue(); + createdEventTriggered.ShouldBeTrue(); createdEtoTriggered.ShouldBeTrue(); } From 6565e35286c07a8064914692e07df012448da9d8 Mon Sep 17 00:00:00 2001 From: Salih Date: Fri, 29 Jul 2022 10:43:40 +0300 Subject: [PATCH 09/12] Update en.json --- .../Volo/Blogging/Localization/Resources/en.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json index 9823d30f73..40c44e55c0 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/en.json @@ -56,6 +56,8 @@ "ShareOn": "Share on", "TitleLengthWarning": "Keep your title size under 60 characters to be SEO friendly!", "ClearCache": "Clear cache", - "ClearCacheConfirmationMessage": "Are you sure you want to clear the cache?" + "ClearCacheConfirmationMessage": "Are you sure you want to clear the cache?", + "MarkdownSupported": "Markdown is supported", + "FileUploadInfo": "Drag, drop, or paste a copied image." } } \ No newline at end of file From a5c18c0151e9590441a515924db26e79e883997e Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 29 Jul 2022 14:36:59 +0300 Subject: [PATCH 10/12] Add new localizations for commercial.abp.io --- .../Commercial/Localization/Resources/en.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Commercial/Localization/Resources/en.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Commercial/Localization/Resources/en.json index caf4a9dbbe..64cefef9af 100644 --- a/abp_io/AbpIoLocalization/AbpIoLocalization/Commercial/Localization/Resources/en.json +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Commercial/Localization/Resources/en.json @@ -735,6 +735,14 @@ "ConfirmedEmailAddressRequiredToStartTrial": "You should have a confirmed email address in order to start a trial license.", "EmailVerificationMailNotSent": "Email verification mail couldn't send.", "GetConfirmationEmail": "Click here to get a confirmation email if you haven't got it before.", - "WhichLicenseTypeYouAreInterestedIn": "Which license type you are interested in?" + "WhichLicenseTypeYouAreInterestedIn": "Which license type you are interested in?", + "DontTakeOurWordForIt": "Don't take our word for it...", + "ReadAbpCommercialUsersWantYouToKnow": "Read what ABP Commercial users want you to know", + "Testimonial_ShortDescription_1": "The modularity of ABP made it possible for the team to deliver in time.", + "Testimonial_ShortDescription_2": "Build new features faster than before.", + "Testimonial_ShortDescription_3": "We start from out-of-the-box features and just focus on what we really need to write.", + "Testimonial_ShortDescription_4": "ABP Commercial was the best fit for our needs.", + "OnlineReviewersOnAbpCommercial": "Online Reviews on ABP Commercial", + "SeeWhatToldAboutAbpCommercial": "See what has been told about ABP Commercial and write your thoughts if you want." } } From cab8f9ea20e8daa5c6e005a95303c93bcd2d1003 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 29 Jul 2022 15:32:57 +0300 Subject: [PATCH 11/12] Update en.json --- .../AbpIoLocalization/Www/Localization/Resources/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json index 826d093ea3..931202033b 100644 --- a/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json @@ -374,7 +374,7 @@ "MasteringAbpFramework_Book_WhoIsThisBookFor_Description": "This book is for web developers who want to learn software architectures and best practices for building\n maintainable web-based solutions using Microsoft technologies and ABP Framework. Basic knowledge of C#\n and ASP.NET Core is necessary to get started with this book.", "ComputersAndTechnology": "Computers & Technology", "BuildingMicroserviceSolutions": "Building Microservice Solutions", - "MicroserviceBookPracticalGuide": "This book is a reference guide for developing and managing microservice-based applications using the ABP Framework. It references the .*NET Microservice Sample Rerefence Application*: eShopOnContainers and discusses the architectural design and implementation approaches using the ABP Framework. Moreover, you will learn the working implementation of an e-shop process like adding products, completing the purchase using PayPal, updating the basket cart item in real-time, shipping a purchased product, and more. Written by the main contributors of the ABP Framework, this book will help you understand how the ABP modularity is used like lego pieces to become a running distributed system. It will discuss the decisions to create a microservice environment and how to develop an application rapidly.By the end of this book, you'll learn how ABP approaches the common microservice complexities such as authorization, distributed transactions, inter-microservice communications, deployment, etc. ", + "MicroserviceBookPracticalGuide": "This book is a reference guide for developing and managing microservice-based applications using the ABP Framework. It references the .NET Microservice Sample Reference Application: eShopOnContainers and discusses the architectural design and implementation approaches using the ABP Framework. By the end of this book, you'll learn how ABP approaches the common microservice complexities such as authorization, distributed transactions, inter-microservice communications, deployment, etc.", "IntroducingMicroservice": "Introducing Microservice", "RunningTheSolution": "Running the Solution", "UnderstandingTheAuthenticationSystem": "Understanding the Authentication System", From 73774eb12b31a7b045178f2caf3f19ff6756993e Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 29 Jul 2022 15:39:33 +0300 Subject: [PATCH 12/12] Update en.json --- .../AbpIoLocalization/Www/Localization/Resources/en.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json index 931202033b..2a5f9a2584 100644 --- a/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json @@ -375,15 +375,9 @@ "ComputersAndTechnology": "Computers & Technology", "BuildingMicroserviceSolutions": "Building Microservice Solutions", "MicroserviceBookPracticalGuide": "This book is a reference guide for developing and managing microservice-based applications using the ABP Framework. It references the .NET Microservice Sample Reference Application: eShopOnContainers and discusses the architectural design and implementation approaches using the ABP Framework. By the end of this book, you'll learn how ABP approaches the common microservice complexities such as authorization, distributed transactions, inter-microservice communications, deployment, etc.", - "IntroducingMicroservice": "Introducing Microservice", + "IntroducingTheSolution": "Introducing the eShopOnAbp Solution", "RunningTheSolution": "Running the Solution", "UnderstandingTheAuthenticationSystem": "Understanding the Authentication System", - "ExploringTheApplications": "Exploring the Applications", - "UnderstandingTheAPIGateways": "Understanding the API Gateways", - "DevelopingTheMicroservices": "Developing the Microservices", - "UnderstandingTheInfrastructure": "Understanding the Infrastructure", - "DiggingInTheUseCases": "Digging in the Use Cases", - "DeployingTheSolution": "Deploying the Solution", "Authors": "Authors", "MicroserviceEBook": "Microservice E-Book", "SelectUITheme": "Select UI Theme",