Browse Source

Introduce IAbpApplication.ApplicationName

pull/13644/head
Halil İbrahim Kalkan 4 years ago
parent
commit
c62af908a4
  1. 6
      framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionApplicationExtensions.cs
  2. 4
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs
  3. 3
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationCreationOptions.cs
  4. 2
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs
  5. 7
      framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs
  6. 15
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs

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

@ -39,4 +39,10 @@ public static class ServiceCollectionApplicationExtensions
{
return await AbpApplicationFactory.CreateAsync(startupModuleType, services, optionsAction);
}
[CanBeNull]
public static string GetApplicationName(this IServiceCollection services)
{
return services.GetSingletonInstance<IAbpApplication>().ApplicationName;
}
}

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

@ -23,6 +23,8 @@ public abstract class AbpApplicationBase : IAbpApplication
public IServiceCollection Services { get; }
public IReadOnlyList<IAbpModuleDescriptor> Modules { get; }
public string ApplicationName { get; }
private bool _configuredServices;
@ -41,6 +43,8 @@ public abstract class AbpApplicationBase : IAbpApplication
var options = new AbpApplicationCreationOptions(services);
optionsAction?.Invoke(options);
ApplicationName = options.ApplicationName;
services.AddSingleton<IAbpApplication>(this);
services.AddSingleton<IModuleContainer>(this);

3
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationCreationOptions.cs

@ -20,6 +20,9 @@ public class AbpApplicationCreationOptions
public AbpConfigurationBuilderOptions Configuration { get; }
public bool SkipConfigureServices { get; set; }
[CanBeNull]
public string ApplicationName { get; set; }
public AbpApplicationCreationOptions([NotNull] IServiceCollection services)
{

2
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs

@ -60,6 +60,6 @@ internal class AbpApplicationWithInternalServiceProvider : AbpApplicationBase, I
public override void Dispose()
{
base.Dispose();
ServiceScope.Dispose();
ServiceScope?.Dispose();
}
}

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

@ -24,6 +24,13 @@ public interface IAbpApplication : IModuleContainer, IDisposable
/// </summary>
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>
/// Calls the Pre/Post/ConfigureServicesAsync methods of the modules.
/// If you use this method, you must have set the <see cref="AbpApplicationCreationOptions.SkipConfigureServices"/>

15
framework/test/Volo.Abp.Core.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs

@ -142,4 +142,19 @@ public class AbpApplication_Initialize_Tests
plugInModule.OnApplicationShutdownIsCalled.ShouldBeTrue();
}
}
[Fact]
public void Should_Set_And_Get_ApplicationName()
{
const string applicationName = "MyApplication";
using (var application = AbpApplicationFactory.Create<IndependentEmptyModule>(options =>
{
options.ApplicationName = applicationName;
}))
{
application.ApplicationName.ShouldBe(applicationName);
application.Services.GetApplicationName().ShouldBe(applicationName);
}
}
}

Loading…
Cancel
Save