Skip to content

Commit

Permalink
Merge pull request #14541 from abpframework/app-instance-id
Browse files Browse the repository at this point in the history
Introduce Application Instance Id & Rename IApplicationNameAccessor to IApplicationInfoAccessor
  • Loading branch information
hikalkan authored Nov 4, 2022
2 parents 1dcd953 + 93ef2a2 commit 8cbf281
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public async static Task<IAbpApplicationWithExternalServiceProvider> AddApplicat
[CanBeNull]
public static string GetApplicationName(this IServiceCollection services)
{
return services.GetSingletonInstance<IApplicationNameAccessor>().ApplicationName;
return services.GetSingletonInstance<IApplicationInfoAccessor>().ApplicationName;
}

[NotNull]
public static string GetApplicationInstanceId(this IServiceCollection services)
{
return services.GetSingletonInstance<IApplicationInfoAccessor>().InstanceId;
}
}
4 changes: 3 additions & 1 deletion framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public abstract class AbpApplicationBase : IAbpApplication

public string ApplicationName { get; }

public string InstanceId { get; } = Guid.NewGuid().ToString();

private bool _configuredServices;

internal AbpApplicationBase(
Expand All @@ -47,7 +49,7 @@ internal AbpApplicationBase(
ApplicationName = GetApplicationName(options);

services.AddSingleton<IAbpApplication>(this);
services.AddSingleton<IApplicationNameAccessor>(this);
services.AddSingleton<IApplicationInfoAccessor>(this);
services.AddSingleton<IModuleContainer>(this);

services.AddCoreServices();
Expand Down
2 changes: 1 addition & 1 deletion framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Volo.Abp;

public interface IAbpApplication :
IModuleContainer,
IApplicationNameAccessor,
IApplicationInfoAccessor,
IDisposable
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Volo.Abp;

public interface IApplicationNameAccessor
public interface IApplicationInfoAccessor
{
/// <summary>
/// Name of the application.
Expand All @@ -11,4 +11,11 @@ public interface IApplicationNameAccessor
/// </summary>
[CanBeNull]
string ApplicationName { get; }

/// <summary>
/// A unique identifier for this application instance.
/// This value changes whenever the application is restarted.
/// </summary>
[NotNull]
string InstanceId { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void Should_Initialize_PlugIn()
}

[Fact]
public void Should_Set_And_Get_ApplicationName()
public void Should_Set_And_Get_ApplicationName_And_InstanceId()
{
var applicationName = "MyApplication";

Expand All @@ -165,10 +165,9 @@ public void Should_Set_And_Get_ApplicationName()

application.Initialize();

application.ServiceProvider
.GetRequiredService<IApplicationNameAccessor>()
.ApplicationName
.ShouldBe(applicationName);
var appInfo = application.ServiceProvider.GetRequiredService<IApplicationInfoAccessor>();
appInfo.ApplicationName.ShouldBe(applicationName);
appInfo.InstanceId.ShouldNotBeNullOrEmpty();
}

using (var application = AbpApplicationFactory.Create<IndependentEmptyModule>(options =>
Expand All @@ -185,7 +184,7 @@ public void Should_Set_And_Get_ApplicationName()
application.Initialize();

application.ServiceProvider
.GetRequiredService<IApplicationNameAccessor>()
.GetRequiredService<IApplicationInfoAccessor>()
.ApplicationName
.ShouldBe(applicationName);
}
Expand All @@ -199,7 +198,7 @@ public void Should_Set_And_Get_ApplicationName()
application.Initialize();

application.ServiceProvider
.GetRequiredService<IApplicationNameAccessor>()
.GetRequiredService<IApplicationInfoAccessor>()
.ApplicationName
.ShouldBe(applicationName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class StaticFeatureSaver : IStaticFeatureSaver, ITransientDependency
protected IFeatureDefinitionRecordRepository FeatureRepository { get; }
protected IFeatureDefinitionSerializer FeatureSerializer { get; }
protected IDistributedCache Cache { get; }
protected IApplicationNameAccessor ApplicationNameAccessor { get; }
protected IApplicationInfoAccessor ApplicationInfoAccessor { get; }
protected IAbpDistributedLock DistributedLock { get; }
protected AbpFeatureOptions FeatureOptions { get; }
protected ICancellationTokenProvider CancellationTokenProvider { get; }
Expand All @@ -35,7 +35,7 @@ public StaticFeatureSaver(
IFeatureDefinitionSerializer featureSerializer,
IDistributedCache cache,
IOptions<AbpDistributedCacheOptions> cacheOptions,
IApplicationNameAccessor applicationNameAccessor,
IApplicationInfoAccessor applicationInfoAccessor,
IAbpDistributedLock distributedLock,
IOptions<AbpFeatureOptions> featureManagementOptions,
ICancellationTokenProvider cancellationTokenProvider)
Expand All @@ -45,7 +45,7 @@ public StaticFeatureSaver(
FeatureRepository = featureRepository;
FeatureSerializer = featureSerializer;
Cache = cache;
ApplicationNameAccessor = applicationNameAccessor;
ApplicationInfoAccessor = applicationInfoAccessor;
DistributedLock = distributedLock;
CancellationTokenProvider = cancellationTokenProvider;
FeatureOptions = featureManagementOptions.Value;
Expand Down Expand Up @@ -249,7 +249,7 @@ private async Task<bool> UpdateChangedFeaturesAsync(

private string GetApplicationDistributedLockKey()
{
return $"{CacheOptions.KeyPrefix}_{ApplicationNameAccessor.ApplicationName}_AbpFeatureUpdateLock";
return $"{CacheOptions.KeyPrefix}_{ApplicationInfoAccessor.ApplicationName}_AbpFeatureUpdateLock";
}

private string GetCommonDistributedLockKey()
Expand All @@ -259,7 +259,7 @@ private string GetCommonDistributedLockKey()

private string GetApplicationHashCacheKey()
{
return $"{CacheOptions.KeyPrefix}_{ApplicationNameAccessor.ApplicationName}_AbpFeaturesHash";
return $"{CacheOptions.KeyPrefix}_{ApplicationInfoAccessor.ApplicationName}_AbpFeaturesHash";
}

private string GetCommonStampCacheKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc
protected IPermissionDefinitionRecordRepository PermissionRepository { get; }
protected IPermissionDefinitionSerializer PermissionSerializer { get; }
protected IDistributedCache Cache { get; }
protected IApplicationNameAccessor ApplicationNameAccessor { get; }
protected IApplicationInfoAccessor ApplicationInfoAccessor { get; }
protected IAbpDistributedLock DistributedLock { get; }
protected AbpPermissionOptions PermissionOptions { get; }
protected ICancellationTokenProvider CancellationTokenProvider { get; }
Expand All @@ -35,7 +35,7 @@ public StaticPermissionSaver(
IPermissionDefinitionSerializer permissionSerializer,
IDistributedCache cache,
IOptions<AbpDistributedCacheOptions> cacheOptions,
IApplicationNameAccessor applicationNameAccessor,
IApplicationInfoAccessor applicationInfoAccessor,
IAbpDistributedLock distributedLock,
IOptions<AbpPermissionOptions> permissionOptions,
ICancellationTokenProvider cancellationTokenProvider)
Expand All @@ -45,7 +45,7 @@ public StaticPermissionSaver(
PermissionRepository = permissionRepository;
PermissionSerializer = permissionSerializer;
Cache = cache;
ApplicationNameAccessor = applicationNameAccessor;
ApplicationInfoAccessor = applicationInfoAccessor;
DistributedLock = distributedLock;
CancellationTokenProvider = cancellationTokenProvider;
PermissionOptions = permissionOptions.Value;
Expand Down Expand Up @@ -249,7 +249,7 @@ private async Task<bool> UpdateChangedPermissionsAsync(

private string GetApplicationDistributedLockKey()
{
return $"{CacheOptions.KeyPrefix}_{ApplicationNameAccessor.ApplicationName}_AbpPermissionUpdateLock";
return $"{CacheOptions.KeyPrefix}_{ApplicationInfoAccessor.ApplicationName}_AbpPermissionUpdateLock";
}

private string GetCommonDistributedLockKey()
Expand All @@ -259,7 +259,7 @@ private string GetCommonDistributedLockKey()

private string GetApplicationHashCacheKey()
{
return $"{CacheOptions.KeyPrefix}_{ApplicationNameAccessor.ApplicationName}_AbpPermissionsHash";
return $"{CacheOptions.KeyPrefix}_{ApplicationInfoAccessor.ApplicationName}_AbpPermissionsHash";
}

private string GetCommonStampCacheKey()
Expand Down

0 comments on commit 8cbf281

Please sign in to comment.