Enable nullable annotations for Volo.Abp.AspNetCore.Components

pull/17062/head
liangshiwei 2 years ago
parent 741461e6c2
commit 287f434a8f

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

@ -20,8 +20,8 @@ namespace Volo.Abp.AspNetCore.Components;
public abstract class AbpComponentBase : OwningComponentBase
{
protected IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(ref _stringLocalizerFactory);
private IStringLocalizerFactory _stringLocalizerFactory;
protected IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(ref _stringLocalizerFactory)!;
private IStringLocalizerFactory? _stringLocalizerFactory;
protected IStringLocalizer L {
get {
@ -33,46 +33,46 @@ public abstract class AbpComponentBase : OwningComponentBase
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 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);
private ILoggerFactory _loggerFactory;
protected ILoggerFactory LoggerFactory => LazyGetRequiredService(ref _loggerFactory)!;
private ILoggerFactory? _loggerFactory;
protected IAuthorizationService AuthorizationService => LazyGetRequiredService(ref _authorizationService);
private IAuthorizationService _authorizationService;
protected IAuthorizationService AuthorizationService => LazyGetRequiredService(ref _authorizationService)!;
private IAuthorizationService? _authorizationService;
protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser);
private ICurrentUser _currentUser;
protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser)!;
private ICurrentUser? _currentUser;
protected ICurrentTenant CurrentTenant => LazyGetRequiredService(ref _currentTenant);
private ICurrentTenant _currentTenant;
protected ICurrentTenant CurrentTenant => LazyGetRequiredService(ref _currentTenant)!;
private ICurrentTenant? _currentTenant;
protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message);
private IUiMessageService _message;
protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message)!;
private IUiMessageService? _message;
protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify);
private IUiNotificationService _notify;
protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify)!;
private IUiNotificationService? _notify;
protected IUserExceptionInformer UserExceptionInformer => LazyGetNonScopedRequiredService(ref _userExceptionInformer);
private IUserExceptionInformer _userExceptionInformer;
protected IUserExceptionInformer UserExceptionInformer => LazyGetNonScopedRequiredService(ref _userExceptionInformer)!;
private IUserExceptionInformer? _userExceptionInformer;
protected IAlertManager AlertManager => LazyGetNonScopedRequiredService(ref _alertManager);
private IAlertManager _alertManager;
protected IAlertManager AlertManager => LazyGetNonScopedRequiredService(ref _alertManager)!;
private IAlertManager? _alertManager;
protected IClock Clock => LazyGetNonScopedRequiredService(ref _clock);
private IClock _clock;
protected IClock Clock => LazyGetNonScopedRequiredService(ref _clock)!;
private IClock? _clock;
protected AlertList Alerts => AlertManager.Alerts;
@ -85,19 +85,19 @@ public abstract class AbpComponentBase : OwningComponentBase
if (ObjectMapperContext == null)
{
return LazyGetRequiredService(ref _objectMapper);
return LazyGetRequiredService(ref _objectMapper)!;
}
return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
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);
@ -111,13 +111,13 @@ public abstract class AbpComponentBase : OwningComponentBase
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)
{
reference = (TRef)ScopedServices.GetService(serviceType);
reference = (TRef?)ScopedServices.GetService(serviceType);
}
return reference;
@ -135,20 +135,20 @@ public abstract class AbpComponentBase : OwningComponentBase
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)
{
reference = (TRef)NonScopedServices.GetService(serviceType);
reference = (TRef?)NonScopedServices.GetService(serviceType);
}
return reference;
}
[Inject]
protected IServiceProvider NonScopedServices { get; set; }
protected IServiceProvider NonScopedServices { get; set; } = default!;
protected virtual IStringLocalizer CreateLocalizer()
{

@ -9,27 +9,27 @@ namespace Volo.Abp.AspNetCore.Components.Alerts;
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));
}
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));
}
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));
}
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));
}
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));
}

@ -9,16 +9,15 @@ public class AlertMessage
get => _text;
set => _text = Check.NotNullOrWhiteSpace(value, nameof(value));
}
private string _text;
private string _text = default!;
public AlertType Type { get; set; }
[CanBeNull]
public string Title { get; set; }
public string? Title { 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;
Text = Check.NotNullOrWhiteSpace(text, nameof(text));

@ -5,13 +5,13 @@ namespace Volo.Abp.AspNetCore.Components.Messages;
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);
}

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

@ -5,11 +5,11 @@ namespace Volo.Abp.AspNetCore.Components.Notifications;
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);
}

@ -6,21 +6,21 @@ namespace Volo.Abp.AspNetCore.Components.Notifications;
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;
}
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;
}
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;
}
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;
}

@ -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="options">Additional options.</param>
/// <returns>Awaitable task.</returns>
Task Go(int? percentage, Action<UiPageProgressOptions> options = null);
Task Go(int? percentage, Action<UiPageProgressOptions>? options = null);
}

@ -6,9 +6,9 @@ namespace Volo.Abp.AspNetCore.Components.Progression;
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;
}

Loading…
Cancel
Save