From d2d1dd4c39223491ae100c42998f4d5729bcb265 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Thu, 17 Feb 2022 12:56:33 +0100 Subject: [PATCH] Add .NET 6 support (#358) * Add .NET 6 target framework --- ...Composer.AspNetCore.Endpoints.Tests.csproj | 2 +- .../API/APIApprovals.cs | 2 +- .../ServiceComposer.AspNetCore.Tests.csproj | 2 +- .../CompositionEndpointBuilder.cs | 2 +- .../CompositionEndpointDataSource.cs | 2 +- .../CompositionHandler.cs | 2 +- .../CompositionOverControllersActionFilter.cs | 2 +- .../EndpointsExtensions.cs | 2 +- .../HttpContextActionResultExtensions.cs | 2 +- .../HttpRequestExtensions.cs | 2 +- .../IEndpointScopedViewModelFactory.cs | 2 +- .../IViewModelFactory.cs | 2 +- .../IViewModelPreviewHandler.cs | 2 +- .../HttpRequestModelBinderExtension.cs | 2 +- .../ModelBinding/RequestModelBinder.cs | 4 ++-- .../ResponseSerializationOptions.cs | 2 +- .../ServiceComposer.AspNetCore.csproj | 7 ++++++- .../ViewModelCompositionOptions.cs | 20 +++++++++---------- 18 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/ServiceComposer.AspNetCore.Endpoints.Tests/ServiceComposer.AspNetCore.Endpoints.Tests.csproj b/src/ServiceComposer.AspNetCore.Endpoints.Tests/ServiceComposer.AspNetCore.Endpoints.Tests.csproj index d698873e..22051052 100644 --- a/src/ServiceComposer.AspNetCore.Endpoints.Tests/ServiceComposer.AspNetCore.Endpoints.Tests.csproj +++ b/src/ServiceComposer.AspNetCore.Endpoints.Tests/ServiceComposer.AspNetCore.Endpoints.Tests.csproj @@ -2,7 +2,7 @@ false - netcoreapp3.1;net5.0 + netcoreapp3.1;net5.0;net6.0 diff --git a/src/ServiceComposer.AspNetCore.Tests/API/APIApprovals.cs b/src/ServiceComposer.AspNetCore.Tests/API/APIApprovals.cs index 462c8325..24a8ef13 100644 --- a/src/ServiceComposer.AspNetCore.Tests/API/APIApprovals.cs +++ b/src/ServiceComposer.AspNetCore.Tests/API/APIApprovals.cs @@ -12,7 +12,7 @@ public class APIApprovals [Fact] [UseReporter(typeof(DiffReporter))] [MethodImpl(MethodImplOptions.NoInlining)] -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER [UseApprovalSubdirectory("NET")] #endif #if NETCOREAPP2_1 diff --git a/src/ServiceComposer.AspNetCore.Tests/ServiceComposer.AspNetCore.Tests.csproj b/src/ServiceComposer.AspNetCore.Tests/ServiceComposer.AspNetCore.Tests.csproj index 9762b723..67b0a581 100644 --- a/src/ServiceComposer.AspNetCore.Tests/ServiceComposer.AspNetCore.Tests.csproj +++ b/src/ServiceComposer.AspNetCore.Tests/ServiceComposer.AspNetCore.Tests.csproj @@ -2,7 +2,7 @@ false - netcoreapp2.1;netcoreapp3.1;net5.0 + netcoreapp2.1;netcoreapp3.1;net5.0;net6.0 diff --git a/src/ServiceComposer.AspNetCore/CompositionEndpointBuilder.cs b/src/ServiceComposer.AspNetCore/CompositionEndpointBuilder.cs index a832e141..582829f5 100644 --- a/src/ServiceComposer.AspNetCore/CompositionEndpointBuilder.cs +++ b/src/ServiceComposer.AspNetCore/CompositionEndpointBuilder.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using System; using System.Collections.Generic; diff --git a/src/ServiceComposer.AspNetCore/CompositionEndpointDataSource.cs b/src/ServiceComposer.AspNetCore/CompositionEndpointDataSource.cs index 2dfd28a8..3c82675b 100644 --- a/src/ServiceComposer.AspNetCore/CompositionEndpointDataSource.cs +++ b/src/ServiceComposer.AspNetCore/CompositionEndpointDataSource.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using System.Collections.Generic; using System.Linq; diff --git a/src/ServiceComposer.AspNetCore/CompositionHandler.cs b/src/ServiceComposer.AspNetCore/CompositionHandler.cs index b84a9f7a..f3ce2712 100644 --- a/src/ServiceComposer.AspNetCore/CompositionHandler.cs +++ b/src/ServiceComposer.AspNetCore/CompositionHandler.cs @@ -85,7 +85,7 @@ public class CompositionHandler } } -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER internal static async Task HandleComposableRequest(HttpContext context, Type[] componentsTypes) { context.Request.EnableBuffering(); diff --git a/src/ServiceComposer.AspNetCore/CompositionOverControllersActionFilter.cs b/src/ServiceComposer.AspNetCore/CompositionOverControllersActionFilter.cs index 4d9bfd36..761dc499 100644 --- a/src/ServiceComposer.AspNetCore/CompositionOverControllersActionFilter.cs +++ b/src/ServiceComposer.AspNetCore/CompositionOverControllersActionFilter.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using System.Diagnostics; using System.Linq; using System.Threading.Tasks; diff --git a/src/ServiceComposer.AspNetCore/EndpointsExtensions.cs b/src/ServiceComposer.AspNetCore/EndpointsExtensions.cs index 15fc77a9..ae1f5e71 100644 --- a/src/ServiceComposer.AspNetCore/EndpointsExtensions.cs +++ b/src/ServiceComposer.AspNetCore/EndpointsExtensions.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using System; using System.Collections.Generic; diff --git a/src/ServiceComposer.AspNetCore/HttpContextActionResultExtensions.cs b/src/ServiceComposer.AspNetCore/HttpContextActionResultExtensions.cs index 5638b568..18590b99 100644 --- a/src/ServiceComposer.AspNetCore/HttpContextActionResultExtensions.cs +++ b/src/ServiceComposer.AspNetCore/HttpContextActionResultExtensions.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; diff --git a/src/ServiceComposer.AspNetCore/HttpRequestExtensions.cs b/src/ServiceComposer.AspNetCore/HttpRequestExtensions.cs index cb15a4cb..3ff4e22c 100644 --- a/src/ServiceComposer.AspNetCore/HttpRequestExtensions.cs +++ b/src/ServiceComposer.AspNetCore/HttpRequestExtensions.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using System; using Microsoft.AspNetCore.Http; diff --git a/src/ServiceComposer.AspNetCore/IEndpointScopedViewModelFactory.cs b/src/ServiceComposer.AspNetCore/IEndpointScopedViewModelFactory.cs index 7983f58e..c2b69df4 100644 --- a/src/ServiceComposer.AspNetCore/IEndpointScopedViewModelFactory.cs +++ b/src/ServiceComposer.AspNetCore/IEndpointScopedViewModelFactory.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER namespace ServiceComposer.AspNetCore { public interface IEndpointScopedViewModelFactory : IViewModelFactory diff --git a/src/ServiceComposer.AspNetCore/IViewModelFactory.cs b/src/ServiceComposer.AspNetCore/IViewModelFactory.cs index c65231e7..cd0b245f 100644 --- a/src/ServiceComposer.AspNetCore/IViewModelFactory.cs +++ b/src/ServiceComposer.AspNetCore/IViewModelFactory.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using Microsoft.AspNetCore.Http; namespace ServiceComposer.AspNetCore diff --git a/src/ServiceComposer.AspNetCore/IViewModelPreviewHandler.cs b/src/ServiceComposer.AspNetCore/IViewModelPreviewHandler.cs index 97c00316..f45f78c0 100644 --- a/src/ServiceComposer.AspNetCore/IViewModelPreviewHandler.cs +++ b/src/ServiceComposer.AspNetCore/IViewModelPreviewHandler.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using System; using System.Threading.Tasks; diff --git a/src/ServiceComposer.AspNetCore/ModelBinding/HttpRequestModelBinderExtension.cs b/src/ServiceComposer.AspNetCore/ModelBinding/HttpRequestModelBinderExtension.cs index 072f6681..4ec52b30 100644 --- a/src/ServiceComposer.AspNetCore/ModelBinding/HttpRequestModelBinderExtension.cs +++ b/src/ServiceComposer.AspNetCore/ModelBinding/HttpRequestModelBinderExtension.cs @@ -1,4 +1,4 @@ -#if NET5_0 || NETCOREAPP3_1 +#if NET5_0_OR_GREATER || NETCOREAPP3_1 using System.Threading.Tasks; using Microsoft.AspNetCore.Http; diff --git a/src/ServiceComposer.AspNetCore/ModelBinding/RequestModelBinder.cs b/src/ServiceComposer.AspNetCore/ModelBinding/RequestModelBinder.cs index d9f6452e..6261ddfb 100644 --- a/src/ServiceComposer.AspNetCore/ModelBinding/RequestModelBinder.cs +++ b/src/ServiceComposer.AspNetCore/ModelBinding/RequestModelBinder.cs @@ -1,4 +1,4 @@ -#if NET5_0 || NETCOREAPP3_1 +#if NET5_0_OR_GREATER || NETCOREAPP3_1 using System; using System.Threading.Tasks; @@ -41,7 +41,7 @@ public RequestModelBinder(IModelBinderFactory modelBinderFactory, IModelMetadata var valueProvider = await CompositeValueProvider.CreateAsync(actionContext, mvcOptions.Value.ValueProviderFactories); -#if NET5_0 +#if NET5_0_OR_GREATER if (modelMetadata.BoundConstructor != null) { throw new NotSupportedException("Record type not supported"); diff --git a/src/ServiceComposer.AspNetCore/ResponseSerializationOptions.cs b/src/ServiceComposer.AspNetCore/ResponseSerializationOptions.cs index 28af4854..d075ddef 100644 --- a/src/ServiceComposer.AspNetCore/ResponseSerializationOptions.cs +++ b/src/ServiceComposer.AspNetCore/ResponseSerializationOptions.cs @@ -6,7 +6,7 @@ namespace ServiceComposer.AspNetCore { -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER public class ResponseSerializationOptions { IServiceCollection services; diff --git a/src/ServiceComposer.AspNetCore/ServiceComposer.AspNetCore.csproj b/src/ServiceComposer.AspNetCore/ServiceComposer.AspNetCore.csproj index 22b80af5..3cb748bd 100644 --- a/src/ServiceComposer.AspNetCore/ServiceComposer.AspNetCore.csproj +++ b/src/ServiceComposer.AspNetCore/ServiceComposer.AspNetCore.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netcoreapp3.1;net5.0 + netstandard2.0;netcoreapp3.1;net5.0;net6.0 @@ -28,6 +28,11 @@ + + + + + diff --git a/src/ServiceComposer.AspNetCore/ViewModelCompositionOptions.cs b/src/ServiceComposer.AspNetCore/ViewModelCompositionOptions.cs index 84e489b8..96b96eb0 100644 --- a/src/ServiceComposer.AspNetCore/ViewModelCompositionOptions.cs +++ b/src/ServiceComposer.AspNetCore/ViewModelCompositionOptions.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Reflection; using Microsoft.Extensions.DependencyInjection; -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Options; @@ -14,7 +14,7 @@ namespace ServiceComposer.AspNetCore public class ViewModelCompositionOptions { readonly CompositionMetadataRegistry _compositionMetadataRegistry = new CompositionMetadataRegistry(); -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER readonly CompositionOverControllersRoutes _compositionOverControllersRoutes = new CompositionOverControllersRoutes(); #endif @@ -25,7 +25,7 @@ internal ViewModelCompositionOptions(IServiceCollection services) Services.AddSingleton(this); Services.AddSingleton(_compositionMetadataRegistry); -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER ResponseSerialization = new ResponseSerializationOptions(Services); #endif } @@ -50,7 +50,7 @@ public void AddTypesRegistrationHandler(Func typesFilter, Action { @@ -217,7 +217,7 @@ internal void InitializeServiceCollection() public IServiceCollection Services { get; private set; } -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER public ResponseSerializationOptions ResponseSerialization { get; } #endif @@ -246,13 +246,13 @@ void RegisterCompositionComponents(Type type) !( typeof(ICompositionRequestsHandler).IsAssignableFrom(type) || typeof(ICompositionEventsSubscriber).IsAssignableFrom(type) -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER || typeof(IEndpointScopedViewModelFactory).IsAssignableFrom(type) #endif ) ) { -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER var message = $"Registered types must be either {nameof(ICompositionRequestsHandler)}, " + $"{nameof(ICompositionEventsSubscriber)}, or {nameof(IEndpointScopedViewModelFactory)}."; #else @@ -273,7 +273,7 @@ void RegisterCompositionComponents(Type type) } } -#if NETCOREAPP3_1 || NET5_0 +#if NETCOREAPP3_1 || NET5_0_OR_GREATER public void RegisterEndpointScopedViewModelFactory() where T: IEndpointScopedViewModelFactory { RegisterCompositionComponents(typeof(T));