From 741461e6c201fdfe2e40a55e5df8ad86ec5717a9 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 6 Jul 2023 16:17:28 +0800 Subject: [PATCH] Enable nullable annotations for Volo.Abp.AspNetCore --- .../Builder/AbpApplicationBuilderExtensions.cs | 2 +- .../AbpAspNetCoreApplicationBuilderExtensions.cs | 2 +- .../VirtualFileSystemApplicationBuilderExtensions.cs | 2 +- .../Hosting/AbpHostingEnvironmentExtensions.cs | 2 +- .../AspNetCore/Internal/ResponseContentTypeHelper.cs | 4 ++-- .../AbpRequestLocalizationOptionsManager.cs | 4 ++-- .../DefaultAbpRequestLocalizationOptionsProvider.cs | 8 ++++---- .../IAbpRequestLocalizationOptionsProvider.cs | 2 +- .../CookieAuthenticationOptionsExtensions.cs | 2 +- .../DependencyInjection/EmptyHostingEnvironment.cs | 12 ++++++------ .../WebApplicationBuilderExtensions.cs | 4 ++-- .../Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj | 2 ++ .../ApplicationInitializationContextExtensions.cs | 5 ++--- .../AbpAuthorizationExceptionHandlerOptions.cs | 2 +- .../DefaultAbpAuthorizationExceptionHandler.cs | 4 ++-- .../DefaultHttpExceptionStatusCodeFinder.cs | 4 ++-- .../Security/AbpSecurityHeadersMiddleware.cs | 6 +++--- .../AspNetCore/Security/AbpSecurityHeadersOptions.cs | 2 +- .../AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs | 4 ++-- .../AbpFileExtensionContentTypeProvider.cs | 6 +++--- .../RazorViewEngineVirtualFileProvider.cs | 2 +- .../HttpContextWebClientInfoProvider.cs | 8 ++++---- .../WebClientInfo/IWebClientInfoProvider.cs | 4 ++-- .../Volo/Abp/ServiceProviderAccessorExtensions.cs | 3 +-- 24 files changed, 48 insertions(+), 48 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs index 8ef3ec8d99..8628c2c803 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs @@ -82,7 +82,7 @@ public static class AbpApplicationBuilderExtensions } public static IApplicationBuilder UseAbpRequestLocalization(this IApplicationBuilder app, - Action optionsAction = null) + Action? optionsAction = null) { app.ApplicationServices .GetRequiredService() diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpAspNetCoreApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpAspNetCoreApplicationBuilderExtensions.cs index 684c948975..20da8d47ce 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpAspNetCoreApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpAspNetCoreApplicationBuilderExtensions.cs @@ -17,7 +17,7 @@ public static class AbpAspNetCoreApplicationBuilderExtensions /// public static IApplicationBuilder UseConfiguredEndpoints( this IApplicationBuilder app, - Action additionalConfigurationAction = null) + Action? additionalConfigurationAction = null) { var options = app.ApplicationServices .GetRequiredService>() diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs index 9fc3603f2e..171747c100 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/VirtualFileSystemApplicationBuilderExtensions.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Builder; public static class VirtualFileSystemApplicationBuilderExtensions { [Obsolete("Use UseStaticFiles() instead. UseVirtualFiles is not needed anymore.")] - public static IApplicationBuilder UseVirtualFiles(this IApplicationBuilder app, Action configure = null) + public static IApplicationBuilder UseVirtualFiles(this IApplicationBuilder app, Action? configure = null) { if (configure != null) { diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Hosting/AbpHostingEnvironmentExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Hosting/AbpHostingEnvironmentExtensions.cs index 15c1d74ccb..8f6b32ba9a 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Hosting/AbpHostingEnvironmentExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Hosting/AbpHostingEnvironmentExtensions.cs @@ -7,7 +7,7 @@ public static class AbpHostingEnvironmentExtensions { public static IConfigurationRoot BuildConfiguration( this IWebHostEnvironment env, - AbpConfigurationBuilderOptions options = null) + AbpConfigurationBuilderOptions? options = null) { options ??= new AbpConfigurationBuilderOptions(); diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Internal/ResponseContentTypeHelper.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Internal/ResponseContentTypeHelper.cs index bff1290835..7a492371b9 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Internal/ResponseContentTypeHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Internal/ResponseContentTypeHelper.cs @@ -28,7 +28,7 @@ public static class ResponseContentTypeHelper string? actionResultContentType, string? httpResponseContentType, (string defaultContentType, Encoding defaultEncoding) @default, - Func getEncoding, + Func getEncoding, out string resolvedContentType, out Encoding resolvedContentTypeEncoding) { @@ -66,7 +66,7 @@ public static class ResponseContentTypeHelper resolvedContentTypeEncoding = defaultContentTypeEncoding; } - public static Encoding GetEncoding(string mediaType) + public static Encoding? GetEncoding(string mediaType) { if (MediaTypeHeaderValue.TryParse(mediaType, out var parsed)) { diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationOptionsManager.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationOptionsManager.cs index 61ec6e2fa3..098a7ef433 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationOptionsManager.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationOptionsManager.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.RequestLocalization; public class AbpRequestLocalizationOptionsManager : AbpDynamicOptionsManager { - private RequestLocalizationOptions _options; + private RequestLocalizationOptions? _options; private readonly IAbpRequestLocalizationOptionsProvider _abpRequestLocalizationOptionsProvider; @@ -19,7 +19,7 @@ public class AbpRequestLocalizationOptionsManager : AbpDynamicOptionsManager _optionsAction; - private RequestLocalizationOptions _requestLocalizationOptions; + private Action? _optionsAction; + private RequestLocalizationOptions? _requestLocalizationOptions; public DefaultAbpRequestLocalizationOptionsProvider(IServiceScopeFactory serviceProviderFactory) { @@ -28,7 +28,7 @@ public class DefaultAbpRequestLocalizationOptionsProvider : IAbpRequestLocalizat _syncSemaphore = new SemaphoreSlim(1, 1); } - public void InitLocalizationOptions(Action optionsAction = null) + public void InitLocalizationOptions(Action? optionsAction = null) { _optionsAction = optionsAction; } @@ -85,7 +85,7 @@ public class DefaultAbpRequestLocalizationOptionsProvider : IAbpRequestLocalizat return _requestLocalizationOptions; } - private static RequestCulture DefaultGetRequestCulture(string defaultLanguage, IReadOnlyList languages) + private static RequestCulture DefaultGetRequestCulture(string? defaultLanguage, IReadOnlyList languages) { if (defaultLanguage == null) { diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs index e26a23ef4d..0b8e85ada2 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.RequestLocalization; public interface IAbpRequestLocalizationOptionsProvider { - void InitLocalizationOptions(Action optionsAction = null); + void InitLocalizationOptions(Action? optionsAction = null); Task GetLocalizationOptionsAsync(); } diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/CookieAuthenticationOptionsExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/CookieAuthenticationOptionsExtensions.cs index f873f3762b..0e33ce87fc 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/CookieAuthenticationOptionsExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/CookieAuthenticationOptionsExtensions.cs @@ -47,7 +47,7 @@ public static class CookieAuthenticationOptionsExtensions var response = await openIdConnectOptions.Backchannel.IntrospectTokenAsync(new TokenIntrospectionRequest { - Address = openIdConnectOptions.Configuration?.IntrospectionEndpoint ?? openIdConnectOptions.Authority.EnsureEndsWith('/') + "connect/introspect", + Address = openIdConnectOptions.Configuration?.IntrospectionEndpoint ?? openIdConnectOptions.Authority!.EnsureEndsWith('/') + "connect/introspect", ClientId = openIdConnectOptions.ClientId, ClientSecret = openIdConnectOptions.ClientSecret, Token = accessToken diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/EmptyHostingEnvironment.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/EmptyHostingEnvironment.cs index 371162f0da..99439b9d70 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/EmptyHostingEnvironment.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/EmptyHostingEnvironment.cs @@ -5,15 +5,15 @@ namespace Microsoft.Extensions.DependencyInjection; internal class EmptyHostingEnvironment : IWebHostEnvironment { - public string EnvironmentName { get; set; } + public string EnvironmentName { get; set; } = default!; - public string ApplicationName { get; set; } + public string ApplicationName { get; set; } = default!; - public string WebRootPath { get; set; } + public string WebRootPath { get; set; } = default!; - public IFileProvider WebRootFileProvider { get; set; } + public IFileProvider WebRootFileProvider { get; set; } = default!; - public string ContentRootPath { get; set; } + public string ContentRootPath { get; set; } = default!; - public IFileProvider ContentRootFileProvider { get; set; } + public IFileProvider ContentRootFileProvider { get; set; } = default!; } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/WebApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/WebApplicationBuilderExtensions.cs index f044348052..00d8b4ab3d 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/WebApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/WebApplicationBuilderExtensions.cs @@ -11,7 +11,7 @@ public static class WebApplicationBuilderExtensions { public static async Task AddApplicationAsync( [NotNull] this WebApplicationBuilder builder, - [CanBeNull] Action optionsAction = null) + Action? optionsAction = null) where TStartupModule : IAbpModule { return await builder.Services.AddApplicationAsync(options => @@ -28,7 +28,7 @@ public static class WebApplicationBuilderExtensions public static async Task AddApplicationAsync( [NotNull] this WebApplicationBuilder builder, [NotNull] Type startupModuleType, - [CanBeNull] Action optionsAction = null) + Action? optionsAction = null) { return await builder.Services.AddApplicationAsync(startupModuleType, options => { diff --git a/framework/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj b/framework/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj index 0fe01e9f2b..20ee51e01f 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj +++ b/framework/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj @@ -5,6 +5,8 @@ net7.0 + enable + Nullable Volo.Abp.AspNetCore Volo.Abp.AspNetCore $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs index 4a57b998c3..045b293489 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs @@ -12,7 +12,7 @@ public static class ApplicationInitializationContextExtensions { public static IApplicationBuilder GetApplicationBuilder(this ApplicationInitializationContext context) { - return context.ServiceProvider.GetRequiredService>().Value; + return context.ServiceProvider.GetRequiredService>().Value!; } public static IWebHostEnvironment GetEnvironment(this ApplicationInitializationContext context) @@ -20,8 +20,7 @@ public static class ApplicationInitializationContextExtensions return context.ServiceProvider.GetRequiredService(); } - [CanBeNull] - public static IWebHostEnvironment GetEnvironmentOrNull(this ApplicationInitializationContext context) + public static IWebHostEnvironment? GetEnvironmentOrNull(this ApplicationInitializationContext context) { return context.ServiceProvider.GetService(); } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpAuthorizationExceptionHandlerOptions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpAuthorizationExceptionHandlerOptions.cs index 73f668cb49..6d1935c0bd 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpAuthorizationExceptionHandlerOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/AbpAuthorizationExceptionHandlerOptions.cs @@ -2,5 +2,5 @@ public class AbpAuthorizationExceptionHandlerOptions { - public string AuthenticationScheme { get; set; } + public string? AuthenticationScheme { get; set; } } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultAbpAuthorizationExceptionHandler.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultAbpAuthorizationExceptionHandler.cs index 0c65fa6124..43eecc4cd2 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultAbpAuthorizationExceptionHandler.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultAbpAuthorizationExceptionHandler.cs @@ -17,11 +17,11 @@ public class DefaultAbpAuthorizationExceptionHandler : IAbpAuthorizationExceptio var isAuthenticated = httpContext.User.Identity?.IsAuthenticated ?? false; var authenticationSchemeProvider = httpContext.RequestServices.GetRequiredService(); - AuthenticationScheme scheme = null; + AuthenticationScheme? scheme = null; if (!handlerOptions.AuthenticationScheme.IsNullOrWhiteSpace()) { - scheme = await authenticationSchemeProvider.GetSchemeAsync(handlerOptions.AuthenticationScheme); + scheme = await authenticationSchemeProvider.GetSchemeAsync(handlerOptions.AuthenticationScheme!); if (scheme == null) { throw new AbpException($"No authentication scheme named {handlerOptions.AuthenticationScheme} was found."); diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs index 39614ad3ad..892b00b2d3 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs @@ -32,7 +32,7 @@ public class DefaultHttpExceptionStatusCodeFinder : IHttpExceptionStatusCodeFind if (exception is IHasErrorCode exceptionWithErrorCode && !exceptionWithErrorCode.Code.IsNullOrWhiteSpace()) { - if (Options.ErrorCodeToHttpStatusCodeMappings.TryGetValue(exceptionWithErrorCode.Code, out var status)) + if (Options.ErrorCodeToHttpStatusCodeMappings.TryGetValue(exceptionWithErrorCode.Code!, out var status)) { return status; } @@ -40,7 +40,7 @@ public class DefaultHttpExceptionStatusCodeFinder : IHttpExceptionStatusCodeFind if (exception is AbpAuthorizationException) { - return httpContext.User.Identity.IsAuthenticated + return httpContext.User.Identity!.IsAuthenticated ? HttpStatusCode.Forbidden : HttpStatusCode.Unauthorized; } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs index b1068bbe85..aea345159a 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs @@ -32,7 +32,7 @@ public class AbpSecurityHeadersMiddleware : IMiddleware, ITransientDependency AddHeader(context, "X-Frame-Options", "SAMEORIGIN"); var requestAcceptTypeHtml = context.Request.Headers["Accept"].Any(x => - x.Contains("text/html") || x.Contains("*/*") || x.Contains("application/xhtml+xml")); + x!.Contains("text/html") || x.Contains("*/*") || x.Contains("application/xhtml+xml")); var endpoint = context.GetEndpoint(); @@ -109,7 +109,7 @@ public class AbpSecurityHeadersMiddleware : IMiddleware, ITransientDependency protected virtual string BuildContentSecurityPolicyValue(HttpContext context) { - var cspValue = Options.Value.ContentSecurityPolicyValue.IsNullOrWhiteSpace() ? DefaultValue : Options.Value.ContentSecurityPolicyValue; + var cspValue = Options.Value.ContentSecurityPolicyValue.IsNullOrWhiteSpace() ? DefaultValue : Options.Value.ContentSecurityPolicyValue!; if (!(Options.Value.UseContentSecurityPolicyScriptNonce && context.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceValue && !string.IsNullOrEmpty(nonceValue))) @@ -128,7 +128,7 @@ public class AbpSecurityHeadersMiddleware : IMiddleware, ITransientDependency } var newScriptSrcValue = scriptSrcValue + nonceStr; - return Options.Value.ContentSecurityPolicyValue.Replace(scriptSrcValue, newScriptSrcValue); + return Options.Value.ContentSecurityPolicyValue!.Replace(scriptSrcValue!, newScriptSrcValue); } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersOptions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersOptions.cs index 9a0bb5cd82..eee1d59243 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersOptions.cs @@ -11,7 +11,7 @@ public class AbpSecurityHeadersOptions public bool UseContentSecurityPolicyScriptNonce { get; set; } - public string ContentSecurityPolicyValue { get; set; } + public string? ContentSecurityPolicyValue { get; set; } public Dictionary Headers { get; } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs index 33f5de3582..b5939bdc44 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs @@ -38,14 +38,14 @@ public class AbpCorrelationIdMiddleware : IMiddleware, ITransientDependency protected virtual string GetCorrelationIdFromRequest(HttpContext context) { - string correlationId = context.Request.Headers[_options.HttpHeaderName]; + string? correlationId = context.Request.Headers[_options.HttpHeaderName]; if (correlationId.IsNullOrEmpty()) { correlationId = Guid.NewGuid().ToString("N"); context.Request.Headers[_options.HttpHeaderName] = correlationId; } - return correlationId; + return correlationId!; } protected virtual void CheckAndSetCorrelationIdOnResponse( diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs index 8701353aa0..da96f2b8a9 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/AbpFileExtensionContentTypeProvider.cs @@ -18,14 +18,14 @@ public class AbpFileExtensionContentTypeProvider : IContentTypeProvider, ITransi var extension = GetExtension(subpath); if (extension == null) { - contentType = null; + contentType = null!; return false; } - return Options.ContentTypeMaps.TryGetValue(extension, out contentType); + return Options.ContentTypeMaps.TryGetValue(extension, out contentType!); } - protected virtual string GetExtension(string path) + protected virtual string? GetExtension(string path) { if (string.IsNullOrWhiteSpace(path)) { diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/RazorViewEngineVirtualFileProvider.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/RazorViewEngineVirtualFileProvider.cs index 97bca5744f..bc0467a6f2 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/RazorViewEngineVirtualFileProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/VirtualFileSystem/RazorViewEngineVirtualFileProvider.cs @@ -16,7 +16,7 @@ public class RazorViewEngineVirtualFileProvider : IFileProvider { _serviceProviderAccessor = serviceProviderAccessor; _fileProvider = new Lazy( - () => serviceProviderAccessor.Value.GetRequiredService(), + () => serviceProviderAccessor.Value!.GetRequiredService(), true ); } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/HttpContextWebClientInfoProvider.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/HttpContextWebClientInfoProvider.cs index ae9f342b06..3c44cda4e3 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/HttpContextWebClientInfoProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/HttpContextWebClientInfoProvider.cs @@ -18,16 +18,16 @@ public class HttpContextWebClientInfoProvider : IWebClientInfoProvider, ITransie HttpContextAccessor = httpContextAccessor; } - public string BrowserInfo => GetBrowserInfo(); + public string? BrowserInfo => GetBrowserInfo(); - public string ClientIpAddress => GetClientIpAddress(); + public string? ClientIpAddress => GetClientIpAddress(); - protected virtual string GetBrowserInfo() + protected virtual string? GetBrowserInfo() { return HttpContextAccessor.HttpContext?.Request?.Headers?["User-Agent"]; } - protected virtual string GetClientIpAddress() + protected virtual string? GetClientIpAddress() { try { diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/IWebClientInfoProvider.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/IWebClientInfoProvider.cs index 708f663daf..abd92597d3 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/IWebClientInfoProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/IWebClientInfoProvider.cs @@ -2,7 +2,7 @@ public interface IWebClientInfoProvider { - string BrowserInfo { get; } + string? BrowserInfo { get; } - string ClientIpAddress { get; } + string? ClientIpAddress { get; } } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ServiceProviderAccessorExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ServiceProviderAccessorExtensions.cs index fd52e9ff0e..da7e40dbdc 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ServiceProviderAccessorExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ServiceProviderAccessorExtensions.cs @@ -7,8 +7,7 @@ namespace Volo.Abp; public static class ServiceProviderAccessorExtensions { - [CanBeNull] - public static HttpContext GetHttpContext(this IServiceProviderAccessor serviceProviderAccessor) + public static HttpContext? GetHttpContext(this IServiceProviderAccessor serviceProviderAccessor) { return serviceProviderAccessor.ServiceProvider.GetRequiredService().HttpContext; }