Browse Source

Enable nullable annotations for Volo.Abp.AspNetCore.Mvc.Client

pull/17094/head
liangshiwei 3 years ago
parent
commit
2df80213d3
  1. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj
  2. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs
  3. 26
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs
  4. 2
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheNameAttribute.cs
  5. 24
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs
  6. 2
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs

2
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.AspNetCore.Mvc.Client</AssemblyName>
<PackageId>Volo.Abp.AspNetCore.Mvc.Client</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

8
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<ApplicationConfigurationDto> GetAsync()
public async Task<ApplicationConfigurationDto?> 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;

26
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<TenantConfiguration> FindAsync(string name)
public async Task<TenantConfiguration?> 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<TenantConfiguration> FindAsync(Guid id)
public async Task<TenantConfiguration?> 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)
{

2
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")!;
}
}

24
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs

@ -861,8 +861,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
uowCache.Add(key, new UnitOfWorkCacheItem<TCacheItem>(value));
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(() =>
UnitOfWorkManager.Current?.OnCompleted(() =>
{
SetRealCache();
return Task.CompletedTask;
@ -928,8 +927,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
uowCache.Add(key, new UnitOfWorkCacheItem<TCacheItem>(value));
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(SetRealCache);
UnitOfWorkManager.Current?.OnCompleted(SetRealCache);
}
else
{
@ -997,8 +995,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
}
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(() =>
UnitOfWorkManager.Current?.OnCompleted(() =>
{
SetRealCache();
return Task.CompletedTask;
@ -1106,8 +1103,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
}
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(SetRealCache);
UnitOfWorkManager.Current?.OnCompleted(SetRealCache);
}
else
{
@ -1311,8 +1307,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
uowCache[key].RemoveValue();
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(() =>
UnitOfWorkManager.Current?.OnCompleted(() =>
{
RemoveRealCache();
return Task.CompletedTask;
@ -1366,8 +1361,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
uowCache[key].RemoveValue();
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(RemoveRealCache);
UnitOfWorkManager.Current?.OnCompleted(RemoveRealCache);
}
else
{
@ -1418,8 +1412,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
}
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(() =>
UnitOfWorkManager.Current?.OnCompleted(() =>
{
RemoveRealCache();
return Task.CompletedTask;
@ -1482,8 +1475,7 @@ public class DistributedCache<TCacheItem, TCacheKey> : IDistributedCache<TCacheI
}
}
// ReSharper disable once PossibleNullReferenceException
UnitOfWorkManager.Current.OnCompleted(RemoveRealCache);
UnitOfWorkManager.Current?.OnCompleted(RemoveRealCache);
}
else
{

2
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs

@ -15,7 +15,7 @@ public class Utf8JsonDistributedCacheSerializer : IDistributedCacheSerializer, I
public byte[] Serialize<T>(T obj)
{
return Encoding.UTF8.GetBytes(JsonSerializer.Serialize(obj));
return Encoding.UTF8.GetBytes(JsonSerializer.Serialize(obj!));
}
public T Deserialize<T>(byte[] bytes)

Loading…
Cancel
Save