Browse Source

Enable nullable annotations for Volo.Abp.Application

pull/17303/head
liangshiwei 3 years ago
parent
commit
c19c22e995
  1. 2
      framework/src/Volo.Abp.Ddd.Application/Volo.Abp.Ddd.Application.csproj
  2. 6
      framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs
  3. 6
      framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs
  4. 20
      framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs

2
framework/src/Volo.Abp.Ddd.Application/Volo.Abp.Ddd.Application.csproj

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.Ddd.Application</AssemblyName>
<PackageId>Volo.Abp.Ddd.Application</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

6
framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyCrudAppService.cs

@ -70,11 +70,11 @@ public abstract class AbstractKeyCrudAppService<TEntity, TGetOutputDto, TGetList
{
protected IRepository<TEntity> Repository { get; }
protected virtual string CreatePolicyName { get; set; }
protected virtual string? CreatePolicyName { get; set; }
protected virtual string UpdatePolicyName { get; set; }
protected virtual string? UpdatePolicyName { get; set; }
protected virtual string DeletePolicyName { get; set; }
protected virtual string? DeletePolicyName { get; set; }
protected AbstractKeyCrudAppService(IRepository<TEntity> repository)
: base(repository)

6
framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs

@ -40,9 +40,9 @@ public abstract class AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGet
{
protected IReadOnlyRepository<TEntity> ReadOnlyRepository { get; }
protected virtual string GetPolicyName { get; set; }
protected virtual string? GetPolicyName { get; set; }
protected virtual string GetListPolicyName { get; set; }
protected virtual string? GetListPolicyName { get; set; }
protected AbstractKeyReadOnlyAppService(IReadOnlyRepository<TEntity> repository)
{
@ -107,7 +107,7 @@ public abstract class AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGet
{
if (!sortInput.Sorting.IsNullOrWhiteSpace())
{
return query.OrderBy(sortInput.Sorting);
return query.OrderBy(sortInput.Sorting!);
}
}

20
framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs

@ -36,10 +36,10 @@ public abstract class ApplicationService :
IGlobalFeatureCheckingEnabled,
ITransientDependency
{
public IAbpLazyServiceProvider LazyServiceProvider { get; set; }
public IAbpLazyServiceProvider LazyServiceProvider { get; set; } = default!;
[Obsolete("Use LazyServiceProvider instead.")]
public IServiceProvider ServiceProvider { get; set; }
public IServiceProvider ServiceProvider { get; set; } = default!;
public static string[] CommonPostfixes { get; set; } = { "AppService", "ApplicationService", "IntService", "IntegrationService", "Service" };
@ -49,7 +49,7 @@ public abstract class ApplicationService :
protected IAsyncQueryableExecuter AsyncExecuter => LazyServiceProvider.LazyGetRequiredService<IAsyncQueryableExecuter>();
protected Type ObjectMapperContext { get; set; }
protected Type? ObjectMapperContext { get; set; }
protected IObjectMapper ObjectMapper => LazyServiceProvider.LazyGetService<IObjectMapper>(provider =>
ObjectMapperContext == null
? provider.GetRequiredService<IObjectMapper>()
@ -85,34 +85,34 @@ public abstract class ApplicationService :
return _localizer;
}
}
private IStringLocalizer _localizer;
private IStringLocalizer? _localizer;
protected Type LocalizationResource {
protected Type? LocalizationResource {
get => _localizationResource;
set {
_localizationResource = value;
_localizer = null;
}
}
private Type _localizationResource = typeof(DefaultResource);
private Type? _localizationResource = typeof(DefaultResource);
protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current;
protected IUnitOfWork? CurrentUnitOfWork => UnitOfWorkManager?.Current;
protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance);
protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName!) ?? NullLogger.Instance);
/// <summary>
/// Checks for given <paramref name="policyName"/>.
/// Throws <see cref="AbpAuthorizationException"/> if given policy has not been granted.
/// </summary>
/// <param name="policyName">The policy name. This method does nothing if given <paramref name="policyName"/> is null or empty.</param>
protected virtual async Task CheckPolicyAsync([CanBeNull] string policyName)
protected virtual async Task CheckPolicyAsync(string? policyName)
{
if (string.IsNullOrEmpty(policyName))
{
return;
}
await AuthorizationService.CheckAsync(policyName);
await AuthorizationService.CheckAsync(policyName!);
}
protected virtual IStringLocalizer CreateLocalizer()

Loading…
Cancel
Save