diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj b/framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj index 95c23d34ad..865ccb9f75 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Components/Volo.Abp.AspNetCore.Components.csproj @@ -5,6 +5,8 @@ net7.0 + enable + Nullable Volo.Abp.AspNetCore.Components Volo.Abp.AspNetCore.Components $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs index 47a0d570bf..6f2df20de8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs +++ b/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 { - 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 _lazyLogger => new Lazy(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true); + private Lazy _lazyLogger => new Lazy(() => 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(ref TService reference) => LazyGetRequiredService(typeof(TService), ref reference); @@ -111,13 +111,13 @@ public abstract class AbpComponentBase : OwningComponentBase return reference; } - protected TService LazyGetService(ref TService reference) => LazyGetService(typeof(TService), ref reference); + protected TService? LazyGetService(ref TService? reference) => LazyGetService(typeof(TService), ref reference); - protected TRef LazyGetService(Type serviceType, ref TRef reference) + protected TRef? LazyGetService(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(ref TService reference) => LazyGetNonScopedService(typeof(TService), ref reference); + protected TService? LazyGetNonScopedService(ref TService? reference) => LazyGetNonScopedService(typeof(TService), ref reference); - protected TRef LazyGetNonScopedService(Type serviceType, ref TRef reference) + protected TRef? LazyGetNonScopedService(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() { diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertList.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertList.cs index 6ea0031352..f450033b01 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertList.cs +++ b/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 { - 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)); } diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs index 7a38e422a0..15de91599b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs @@ -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)); diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/IUiMessageService.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/IUiMessageService.cs index 86e878d2a9..9e8d65fdde 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/IUiMessageService.cs +++ b/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 { - Task Info(string message, string title = null, Action options = null); + Task Info(string message, string? title = null, Action? options = null); - Task Success(string message, string title = null, Action options = null); + Task Success(string message, string? title = null, Action? options = null); - Task Warn(string message, string title = null, Action options = null); + Task Warn(string message, string? title = null, Action? options = null); - Task Error(string message, string title = null, Action options = null); + Task Error(string message, string? title = null, Action? options = null); - Task Confirm(string message, string title = null, Action options = null); + Task Confirm(string message, string? title = null, Action? options = null); } diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageEventArgs.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageEventArgs.cs index 4d73fb2812..adae13a4c2 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageEventArgs.cs +++ b/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 TaskCompletionSource Callback { get; } + public TaskCompletionSource Callback { get; } = default!; } diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/IUiNotificationService.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/IUiNotificationService.cs index 394fdec2a7..d637943af0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/IUiNotificationService.cs +++ b/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 { - Task Info(string message, string title = null, Action options = null); + Task Info(string message, string? title = null, Action? options = null); - Task Success(string message, string title = null, Action options = null); + Task Success(string message, string? title = null, Action? options = null); - Task Warn(string message, string title = null, Action options = null); + Task Warn(string message, string? title = null, Action? options = null); - Task Error(string message, string title = null, Action options = null); + Task Error(string message, string? title = null, Action? options = null); } diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/NullUiNotificationService.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/NullUiNotificationService.cs index 6c47586325..e75b1f3524 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/NullUiNotificationService.cs +++ b/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 Task Info(string message, string title = null, Action options = null) + public Task Info(string message, string? title = null, Action? options = null) { return Task.CompletedTask; } - public Task Success(string message, string title = null, Action options = null) + public Task Success(string message, string? title = null, Action? options = null) { return Task.CompletedTask; } - public Task Warn(string message, string title = null, Action options = null) + public Task Warn(string message, string? title = null, Action? options = null) { return Task.CompletedTask; } - public Task Error(string message, string title = null, Action options = null) + public Task Error(string message, string? title = null, Action? options = null) { return Task.CompletedTask; } diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/IUiPageProgressService.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/IUiPageProgressService.cs index 156c763722..1d32c86dc0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/IUiPageProgressService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/IUiPageProgressService.cs @@ -16,5 +16,5 @@ public interface IUiPageProgressService /// Value of the progress from 0 to 100, or null for indeterminate progress. /// Additional options. /// Awaitable task. - Task Go(int? percentage, Action options = null); + Task Go(int? percentage, Action? options = null); } diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/NullUiPageProgressService.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/NullUiPageProgressService.cs index 2277122418..52f97f23d5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Progression/NullUiPageProgressService.cs +++ b/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 event EventHandler ProgressChanged; + public event EventHandler ProgressChanged = default!; - public Task Go(int? percentage, Action options = null) + public Task Go(int? percentage, Action? options = null) { return Task.CompletedTask; }