Browse Source

Introduce IApplicationNameAccessor

pull/13644/head
Halil İbrahim Kalkan 4 years ago
parent
commit
f220de7fe3
  1. 2
      framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs
  2. 1
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs
  3. 16
      framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs
  4. 11
      framework/src/Volo.Abp.Core/Volo/Abp/IApplicationNameAccessor.cs
  5. 7
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs

2
framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs

@ -43,6 +43,6 @@ public static class ServiceCollectionApplicationExtensions
[CanBeNull] [CanBeNull]
public static string GetApplicationName(this IServiceCollection services) public static string GetApplicationName(this IServiceCollection services)
{ {
return services.GetSingletonInstance<IAbpApplication>().ApplicationName; return services.GetSingletonInstance<IApplicationNameAccessor>().ApplicationName;
} }
} }

1
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs

@ -47,6 +47,7 @@ public abstract class AbpApplicationBase : IAbpApplication
ApplicationName = options.ApplicationName; ApplicationName = options.ApplicationName;
services.AddSingleton<IAbpApplication>(this); services.AddSingleton<IAbpApplication>(this);
services.AddSingleton<IApplicationNameAccessor>(this);
services.AddSingleton<IModuleContainer>(this); services.AddSingleton<IModuleContainer>(this);
services.AddCoreServices(); services.AddCoreServices();

16
framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs

@ -5,7 +5,10 @@ using Volo.Abp.Modularity;
namespace Volo.Abp; namespace Volo.Abp;
public interface IAbpApplication : IModuleContainer, IDisposable public interface IAbpApplication :
IModuleContainer,
IApplicationNameAccessor,
IDisposable
{ {
/// <summary> /// <summary>
/// Type of the startup (entrance) module of the application. /// 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. /// This can not be used before initialize the application.
/// </summary> /// </summary>
IServiceProvider ServiceProvider { get; } IServiceProvider ServiceProvider { get; }
/// <summary>
/// Name of the application.
/// This is useful for systems with multiple applications, to distinguish
/// resources of the applications located together.
/// </summary>
string ApplicationName { get; }
/// <summary> /// <summary>
/// Calls the Pre/Post/ConfigureServicesAsync methods of the modules. /// Calls the Pre/Post/ConfigureServicesAsync methods of the modules.
/// If you use this method, you must have set the <see cref="AbpApplicationCreationOptions.SkipConfigureServices"/> /// If you use this method, you must have set the <see cref="AbpApplicationCreationOptions.SkipConfigureServices"/>
@ -47,4 +43,4 @@ public interface IAbpApplication : IModuleContainer, IDisposable
/// Used to gracefully shutdown the application and all modules. /// Used to gracefully shutdown the application and all modules.
/// </summary> /// </summary>
void Shutdown(); void Shutdown();
} }

11
framework/src/Volo.Abp.Core/Volo/Abp/IApplicationNameAccessor.cs

@ -0,0 +1,11 @@
namespace Volo.Abp;
public interface IApplicationNameAccessor
{
/// <summary>
/// Name of the application.
/// This is useful for systems with multiple applications, to distinguish
/// resources of the applications located together.
/// </summary>
string ApplicationName { get; }
}

7
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.ApplicationName.ShouldBe(applicationName);
application.Services.GetApplicationName().ShouldBe(applicationName); application.Services.GetApplicationName().ShouldBe(applicationName);
application.Initialize();
application.ServiceProvider
.GetRequiredService<IApplicationNameAccessor>()
.ApplicationName
.ShouldBe(applicationName);
} }
} }

Loading…
Cancel
Save