From 2df80213d3d4f3972bf43f4bf90ab53e123f30dc Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 10 Jul 2023 17:47:35 +0800 Subject: [PATCH] Enable nullable annotations for Volo.Abp.AspNetCore.Mvc.Client --- .../Volo.Abp.AspNetCore.Mvc.Client.csproj | 2 ++ ...MvcCachedApplicationConfigurationClient.cs | 8 +++--- .../Mvc/Client/MvcRemoteTenantStore.cs | 26 +++++++++---------- .../Volo/Abp/Caching/CacheNameAttribute.cs | 2 +- .../Volo/Abp/Caching/DistributedCache.cs | 24 ++++++----------- .../Utf8JsonDistributedCacheSerializer.cs | 2 +- 6 files changed, 29 insertions(+), 35 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj index 2e5a66d740..39f753a6c0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj @@ -5,6 +5,8 @@ net7.0 + enable + Nullable Volo.Abp.AspNetCore.Mvc.Client Volo.Abp.AspNetCore.Mvc.Client $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs index 6f2cc1a05f..eb3c84bc78 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs @@ -37,7 +37,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu Cache = cache; } - public async Task GetAsync() + public async Task GetAsync() { var cacheKey = CreateCacheKey(); var httpContext = HttpContextAccessor?.HttpContext; @@ -47,14 +47,14 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu return configuration; } - configuration = await Cache.GetOrAddAsync( + configuration = (await Cache.GetOrAddAsync( cacheKey, async () => await GetRemoteConfigurationAsync(), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.ApplicationConfigurationDtoCacheAbsoluteExpiration } - ); + ))!; if (httpContext != null) { @@ -85,7 +85,7 @@ public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigu return config; } - public ApplicationConfigurationDto Get() + public ApplicationConfigurationDto? Get() { var cacheKey = CreateCacheKey(); var httpContext = HttpContextAccessor?.HttpContext; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs index 3f091f8db8..7b3670eb2a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs @@ -31,7 +31,7 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency Options = options.Value; } - public async Task FindAsync(string name) + public async Task FindAsync(string name) { var cacheKey = CreateCacheKey(name); var httpContext = HttpContextAccessor?.HttpContext; @@ -41,14 +41,14 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency return tenantConfiguration; } - tenantConfiguration = await Cache.GetOrAddAsync( + tenantConfiguration = (await Cache.GetOrAddAsync( cacheKey, - async () => CreateTenantConfiguration(await TenantAppService.FindTenantByNameAsync(name)), + async () => CreateTenantConfiguration(await TenantAppService.FindTenantByNameAsync(name))!, () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.TenantConfigurationCacheAbsoluteExpiration } - ); + ))!; if (httpContext != null) { @@ -58,7 +58,7 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency return tenantConfiguration; } - public async Task FindAsync(Guid id) + public async Task FindAsync(Guid id) { var cacheKey = CreateCacheKey(id); var httpContext = HttpContextAccessor?.HttpContext; @@ -68,14 +68,14 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency return tenantConfiguration; } - tenantConfiguration = await Cache.GetOrAddAsync( + tenantConfiguration = (await Cache.GetOrAddAsync( cacheKey, - async () => CreateTenantConfiguration(await TenantAppService.FindTenantByIdAsync(id)), + async () => CreateTenantConfiguration(await TenantAppService.FindTenantByIdAsync(id))!, () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.TenantConfigurationCacheAbsoluteExpiration } - ); + ))!; if (httpContext != null) { @@ -97,12 +97,12 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency tenantConfiguration = Cache.GetOrAdd( cacheKey, - () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await TenantAppService.FindTenantByNameAsync(name))), + () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await TenantAppService.FindTenantByNameAsync(name))!), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.TenantConfigurationCacheAbsoluteExpiration } - ); + )!; if (httpContext != null) { @@ -124,12 +124,12 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency tenantConfiguration = Cache.GetOrAdd( cacheKey, - () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await TenantAppService.FindTenantByIdAsync(id))), + () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await TenantAppService.FindTenantByIdAsync(id))!), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.TenantConfigurationCacheAbsoluteExpiration } - ); + )!; if (httpContext != null) { @@ -139,7 +139,7 @@ public class MvcRemoteTenantStore : ITenantStore, ITransientDependency return tenantConfiguration; } - protected virtual TenantConfiguration CreateTenantConfiguration(FindTenantResultDto tenantResultDto) + protected virtual TenantConfiguration? CreateTenantConfiguration(FindTenantResultDto tenantResultDto) { if (!tenantResultDto.Success || tenantResultDto.TenantId == null) { diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheNameAttribute.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheNameAttribute.cs index c49225acbf..53a7919ebb 100644 --- a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheNameAttribute.cs +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheNameAttribute.cs @@ -33,6 +33,6 @@ public class CacheNameAttribute : Attribute return cacheNameAttribute.Name; } - return cacheItemType.FullName.RemovePostFix("CacheItem")!; + return cacheItemType.FullName!.RemovePostFix("CacheItem")!; } } diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs index 03e42b5d92..ae571cb5f9 100644 --- a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs @@ -861,8 +861,7 @@ public class DistributedCache : IDistributedCache(value)); } - // ReSharper disable once PossibleNullReferenceException - UnitOfWorkManager.Current.OnCompleted(() => + UnitOfWorkManager.Current?.OnCompleted(() => { SetRealCache(); return Task.CompletedTask; @@ -928,8 +927,7 @@ public class DistributedCache : IDistributedCache(value)); } - // ReSharper disable once PossibleNullReferenceException - UnitOfWorkManager.Current.OnCompleted(SetRealCache); + UnitOfWorkManager.Current?.OnCompleted(SetRealCache); } else { @@ -997,8 +995,7 @@ public class DistributedCache : IDistributedCache + UnitOfWorkManager.Current?.OnCompleted(() => { SetRealCache(); return Task.CompletedTask; @@ -1106,8 +1103,7 @@ public class DistributedCache : IDistributedCache : IDistributedCache + UnitOfWorkManager.Current?.OnCompleted(() => { RemoveRealCache(); return Task.CompletedTask; @@ -1366,8 +1361,7 @@ public class DistributedCache : IDistributedCache : IDistributedCache + UnitOfWorkManager.Current?.OnCompleted(() => { RemoveRealCache(); return Task.CompletedTask; @@ -1482,8 +1475,7 @@ public class DistributedCache : IDistributedCache(T obj) { - return Encoding.UTF8.GetBytes(JsonSerializer.Serialize(obj)); + return Encoding.UTF8.GetBytes(JsonSerializer.Serialize(obj!)); } public T Deserialize(byte[] bytes)