From f220de7fe3d47fc469783837ac65a60da7c949ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 15 Aug 2022 16:40:37 +0300 Subject: [PATCH] Introduce IApplicationNameAccessor --- .../ServiceCollectionApplicationExtensions.cs | 2 +- .../Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs | 1 + .../Volo.Abp.Core/Volo/Abp/IAbpApplication.cs | 16 ++++++---------- .../Volo/Abp/IApplicationNameAccessor.cs | 11 +++++++++++ .../Volo/Abp/AbpApplication_Initialize_Tests.cs | 7 +++++++ 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 framework/src/Volo.Abp.Core/Volo/Abp/IApplicationNameAccessor.cs diff --git a/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs index 204d582ca5..72ce661ed5 100644 --- a/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs +++ b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs @@ -43,6 +43,6 @@ public static class ServiceCollectionApplicationExtensions [CanBeNull] public static string GetApplicationName(this IServiceCollection services) { - return services.GetSingletonInstance().ApplicationName; + return services.GetSingletonInstance().ApplicationName; } } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs b/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs index e24403d0e3..87ddf14c1b 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs @@ -47,6 +47,7 @@ public abstract class AbpApplicationBase : IAbpApplication ApplicationName = options.ApplicationName; services.AddSingleton(this); + services.AddSingleton(this); services.AddSingleton(this); services.AddCoreServices(); diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs b/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs index e132df5a59..35542ee91f 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs @@ -5,7 +5,10 @@ using Volo.Abp.Modularity; namespace Volo.Abp; -public interface IAbpApplication : IModuleContainer, IDisposable +public interface IAbpApplication : + IModuleContainer, + IApplicationNameAccessor, + IDisposable { /// /// Type of the startup (entrance) module of the application. @@ -23,14 +26,7 @@ public interface IAbpApplication : IModuleContainer, IDisposable /// This can not be used before initialize the application. /// IServiceProvider ServiceProvider { get; } - - /// - /// Name of the application. - /// This is useful for systems with multiple applications, to distinguish - /// resources of the applications located together. - /// - string ApplicationName { get; } - + /// /// Calls the Pre/Post/ConfigureServicesAsync methods of the modules. /// If you use this method, you must have set the @@ -47,4 +43,4 @@ public interface IAbpApplication : IModuleContainer, IDisposable /// Used to gracefully shutdown the application and all modules. /// void Shutdown(); -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/IApplicationNameAccessor.cs b/framework/src/Volo.Abp.Core/Volo/Abp/IApplicationNameAccessor.cs new file mode 100644 index 0000000000..0047fcbcdf --- /dev/null +++ b/framework/src/Volo.Abp.Core/Volo/Abp/IApplicationNameAccessor.cs @@ -0,0 +1,11 @@ +namespace Volo.Abp; + +public interface IApplicationNameAccessor +{ + /// + /// Name of the application. + /// This is useful for systems with multiple applications, to distinguish + /// resources of the applications located together. + /// + string ApplicationName { get; } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs index 60f5028caa..9eff208198 100644 --- a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs +++ b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs @@ -156,6 +156,13 @@ public class AbpApplication_Initialize_Tests { application.ApplicationName.ShouldBe(applicationName); application.Services.GetApplicationName().ShouldBe(applicationName); + + application.Initialize(); + + application.ServiceProvider + .GetRequiredService() + .ApplicationName + .ShouldBe(applicationName); } }