Browse Source

Enable nullable annotations for Volo.Abp.AspNetCore.Components

pull/17062/head
liangshiwei 3 years ago
parent
commit
287f434a8f
  1. 2
      framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj
  2. 70
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs
  3. 10
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertList.cs
  4. 7
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs
  5. 10
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/IUiMessageService.cs
  6. 2
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageEventArgs.cs
  7. 8
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/IUiNotificationService.cs
  8. 8
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/NullUiNotificationService.cs
  9. 2
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/IUiPageProgressService.cs
  10. 4
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/NullUiPageProgressService.cs

2
framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj

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

70
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs

@ -20,8 +20,8 @@ namespace Volo.Abp.AspNetCore.Components;
public abstract class AbpComponentBase : OwningComponentBase public abstract class AbpComponentBase : OwningComponentBase
{ {
protected IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(ref _stringLocalizerFactory); protected IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(ref _stringLocalizerFactory)!;
private IStringLocalizerFactory _stringLocalizerFactory; private IStringLocalizerFactory? _stringLocalizerFactory;
protected IStringLocalizer L { protected IStringLocalizer L {
get { get {
@ -33,46 +33,46 @@ public abstract class AbpComponentBase : OwningComponentBase
return _localizer; return _localizer;
} }
} }
private IStringLocalizer _localizer; private IStringLocalizer? _localizer;
protected Type LocalizationResource { protected Type? LocalizationResource {
get => _localizationResource; get => _localizationResource;
set { set {
_localizationResource = value; _localizationResource = value;
_localizer = null; _localizer = null;
} }
} }
private Type _localizationResource = typeof(DefaultResource); private Type? _localizationResource = typeof(DefaultResource);
protected ILogger Logger => _lazyLogger.Value; protected ILogger Logger => _lazyLogger.Value;
private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true); private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName!) ?? NullLogger.Instance, true);
protected ILoggerFactory LoggerFactory => LazyGetRequiredService(ref _loggerFactory); protected ILoggerFactory LoggerFactory => LazyGetRequiredService(ref _loggerFactory)!;
private ILoggerFactory _loggerFactory; private ILoggerFactory? _loggerFactory;
protected IAuthorizationService AuthorizationService => LazyGetRequiredService(ref _authorizationService); protected IAuthorizationService AuthorizationService => LazyGetRequiredService(ref _authorizationService)!;
private IAuthorizationService _authorizationService; private IAuthorizationService? _authorizationService;
protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser); protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser)!;
private ICurrentUser _currentUser; private ICurrentUser? _currentUser;
protected ICurrentTenant CurrentTenant => LazyGetRequiredService(ref _currentTenant); protected ICurrentTenant CurrentTenant => LazyGetRequiredService(ref _currentTenant)!;
private ICurrentTenant _currentTenant; private ICurrentTenant? _currentTenant;
protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message); protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message)!;
private IUiMessageService _message; private IUiMessageService? _message;
protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify); protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify)!;
private IUiNotificationService _notify; private IUiNotificationService? _notify;
protected IUserExceptionInformer UserExceptionInformer => LazyGetNonScopedRequiredService(ref _userExceptionInformer); protected IUserExceptionInformer UserExceptionInformer => LazyGetNonScopedRequiredService(ref _userExceptionInformer)!;
private IUserExceptionInformer _userExceptionInformer; private IUserExceptionInformer? _userExceptionInformer;
protected IAlertManager AlertManager => LazyGetNonScopedRequiredService(ref _alertManager); protected IAlertManager AlertManager => LazyGetNonScopedRequiredService(ref _alertManager)!;
private IAlertManager _alertManager; private IAlertManager? _alertManager;
protected IClock Clock => LazyGetNonScopedRequiredService(ref _clock); protected IClock Clock => LazyGetNonScopedRequiredService(ref _clock)!;
private IClock _clock; private IClock? _clock;
protected AlertList Alerts => AlertManager.Alerts; protected AlertList Alerts => AlertManager.Alerts;
@ -85,19 +85,19 @@ public abstract class AbpComponentBase : OwningComponentBase
if (ObjectMapperContext == null) if (ObjectMapperContext == null)
{ {
return LazyGetRequiredService(ref _objectMapper); return LazyGetRequiredService(ref _objectMapper)!;
} }
return LazyGetRequiredService( return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext), typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
ref _objectMapper ref _objectMapper
); )!;
} }
} }
private IObjectMapper _objectMapper; private IObjectMapper? _objectMapper;
protected Type ObjectMapperContext { get; set; } protected Type? ObjectMapperContext { get; set; }
protected TService LazyGetRequiredService<TService>(ref TService reference) => LazyGetRequiredService(typeof(TService), ref reference); protected TService LazyGetRequiredService<TService>(ref TService reference) => LazyGetRequiredService(typeof(TService), ref reference);
@ -111,13 +111,13 @@ public abstract class AbpComponentBase : OwningComponentBase
return reference; return reference;
} }
protected TService LazyGetService<TService>(ref TService reference) => LazyGetService(typeof(TService), ref reference); protected TService? LazyGetService<TService>(ref TService? reference) => LazyGetService(typeof(TService), ref reference);
protected TRef LazyGetService<TRef>(Type serviceType, ref TRef reference) protected TRef? LazyGetService<TRef>(Type serviceType, ref TRef? reference)
{ {
if (reference == null) if (reference == null)
{ {
reference = (TRef)ScopedServices.GetService(serviceType); reference = (TRef?)ScopedServices.GetService(serviceType);
} }
return reference; return reference;
@ -135,20 +135,20 @@ public abstract class AbpComponentBase : OwningComponentBase
return reference; return reference;
} }
protected TService LazyGetNonScopedService<TService>(ref TService reference) => LazyGetNonScopedService(typeof(TService), ref reference); protected TService? LazyGetNonScopedService<TService>(ref TService? reference) => LazyGetNonScopedService(typeof(TService), ref reference);
protected TRef LazyGetNonScopedService<TRef>(Type serviceType, ref TRef reference) protected TRef? LazyGetNonScopedService<TRef>(Type serviceType, ref TRef? reference)
{ {
if (reference == null) if (reference == null)
{ {
reference = (TRef)NonScopedServices.GetService(serviceType); reference = (TRef?)NonScopedServices.GetService(serviceType);
} }
return reference; return reference;
} }
[Inject] [Inject]
protected IServiceProvider NonScopedServices { get; set; } protected IServiceProvider NonScopedServices { get; set; } = default!;
protected virtual IStringLocalizer CreateLocalizer() protected virtual IStringLocalizer CreateLocalizer()
{ {

10
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertList.cs

@ -9,27 +9,27 @@ namespace Volo.Abp.AspNetCore.Components.Alerts;
public class AlertList : ObservableCollection<AlertMessage> public class AlertList : ObservableCollection<AlertMessage>
{ {
public void Add(AlertType type, string text, string title = null, bool dismissible = true) public void Add(AlertType type, string text, string? title = null, bool dismissible = true)
{ {
Add(new AlertMessage(type, text, title, dismissible)); Add(new AlertMessage(type, text, title, dismissible));
} }
public void Info(string text, string title = null, bool dismissible = true) public void Info(string text, string? title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Info, text, title, dismissible)); Add(new AlertMessage(AlertType.Info, text, title, dismissible));
} }
public void Warning(string text, string title = null, bool dismissible = true) public void Warning(string text, string? title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Warning, text, title, dismissible)); Add(new AlertMessage(AlertType.Warning, text, title, dismissible));
} }
public void Danger(string text, string title = null, bool dismissible = true) public void Danger(string text, string? title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Danger, text, title, dismissible)); Add(new AlertMessage(AlertType.Danger, text, title, dismissible));
} }
public void Success(string text, string title = null, bool dismissible = true) public void Success(string text, string? title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Success, text, title, dismissible)); Add(new AlertMessage(AlertType.Success, text, title, dismissible));
} }

7
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs

@ -9,16 +9,15 @@ public class AlertMessage
get => _text; get => _text;
set => _text = Check.NotNullOrWhiteSpace(value, nameof(value)); set => _text = Check.NotNullOrWhiteSpace(value, nameof(value));
} }
private string _text; private string _text = default!;
public AlertType Type { get; set; } public AlertType Type { get; set; }
[CanBeNull] public string? Title { get; set; }
public string Title { get; set; }
public bool Dismissible { get; set; } public bool Dismissible { get; set; }
public AlertMessage(AlertType type, [NotNull] string text, string title = null, bool dismissible = true) public AlertMessage(AlertType type, [NotNull] string text, string? title = null, bool dismissible = true)
{ {
Type = type; Type = type;
Text = Check.NotNullOrWhiteSpace(text, nameof(text)); Text = Check.NotNullOrWhiteSpace(text, nameof(text));

10
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/IUiMessageService.cs

@ -5,13 +5,13 @@ namespace Volo.Abp.AspNetCore.Components.Messages;
public interface IUiMessageService public interface IUiMessageService
{ {
Task Info(string message, string title = null, Action<UiMessageOptions> options = null); Task Info(string message, string? title = null, Action<UiMessageOptions>? options = null);
Task Success(string message, string title = null, Action<UiMessageOptions> options = null); Task Success(string message, string? title = null, Action<UiMessageOptions>? options = null);
Task Warn(string message, string title = null, Action<UiMessageOptions> options = null); Task Warn(string message, string? title = null, Action<UiMessageOptions>? options = null);
Task Error(string message, string title = null, Action<UiMessageOptions> options = null); Task Error(string message, string? title = null, Action<UiMessageOptions>? options = null);
Task<bool> Confirm(string message, string title = null, Action<UiMessageOptions> options = null); Task<bool> Confirm(string message, string? title = null, Action<UiMessageOptions>? options = null);
} }

2
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageEventArgs.cs

@ -30,5 +30,5 @@ public class UiMessageEventArgs : EventArgs
public UiMessageOptions Options { get; } public UiMessageOptions Options { get; }
public TaskCompletionSource<bool> Callback { get; } public TaskCompletionSource<bool> Callback { get; } = default!;
} }

8
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/IUiNotificationService.cs

@ -5,11 +5,11 @@ namespace Volo.Abp.AspNetCore.Components.Notifications;
public interface IUiNotificationService public interface IUiNotificationService
{ {
Task Info(string message, string title = null, Action<UiNotificationOptions> options = null); Task Info(string message, string? title = null, Action<UiNotificationOptions>? options = null);
Task Success(string message, string title = null, Action<UiNotificationOptions> options = null); Task Success(string message, string? title = null, Action<UiNotificationOptions>? options = null);
Task Warn(string message, string title = null, Action<UiNotificationOptions> options = null); Task Warn(string message, string? title = null, Action<UiNotificationOptions>? options = null);
Task Error(string message, string title = null, Action<UiNotificationOptions> options = null); Task Error(string message, string? title = null, Action<UiNotificationOptions>? options = null);
} }

8
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/NullUiNotificationService.cs

@ -6,21 +6,21 @@ namespace Volo.Abp.AspNetCore.Components.Notifications;
public class NullUiNotificationService : IUiNotificationService, ITransientDependency public class NullUiNotificationService : IUiNotificationService, ITransientDependency
{ {
public Task Info(string message, string title = null, Action<UiNotificationOptions> options = null) public Task Info(string message, string? title = null, Action<UiNotificationOptions>? options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Success(string message, string title = null, Action<UiNotificationOptions> options = null) public Task Success(string message, string? title = null, Action<UiNotificationOptions>? options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Warn(string message, string title = null, Action<UiNotificationOptions> options = null) public Task Warn(string message, string? title = null, Action<UiNotificationOptions>? options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Error(string message, string title = null, Action<UiNotificationOptions> options = null) public Task Error(string message, string? title = null, Action<UiNotificationOptions>? options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }

2
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/IUiPageProgressService.cs

@ -16,5 +16,5 @@ public interface IUiPageProgressService
/// <param name="percentage">Value of the progress from 0 to 100, or null for indeterminate progress.</param> /// <param name="percentage">Value of the progress from 0 to 100, or null for indeterminate progress.</param>
/// <param name="options">Additional options.</param> /// <param name="options">Additional options.</param>
/// <returns>Awaitable task.</returns> /// <returns>Awaitable task.</returns>
Task Go(int? percentage, Action<UiPageProgressOptions> options = null); Task Go(int? percentage, Action<UiPageProgressOptions>? options = null);
} }

4
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/NullUiPageProgressService.cs

@ -6,9 +6,9 @@ namespace Volo.Abp.AspNetCore.Components.Progression;
public class NullUiPageProgressService : IUiPageProgressService, ISingletonDependency public class NullUiPageProgressService : IUiPageProgressService, ISingletonDependency
{ {
public event EventHandler<UiPageProgressEventArgs> ProgressChanged; public event EventHandler<UiPageProgressEventArgs> ProgressChanged = default!;
public Task Go(int? percentage, Action<UiPageProgressOptions> options = null) public Task Go(int? percentage, Action<UiPageProgressOptions>? options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }

Loading…
Cancel
Save