From 0772889df419c3a306ab5ead8c04a3c8efcaf62c Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Fri, 31 Jan 2025 10:58:06 +0300 Subject: [PATCH 01/17] upgrade dotnet version --- .github/workflows/publish.yml | 4 ++-- .github/workflows/regular-checks-docs.yml | 2 +- .github/workflows/regular-checks-project.yml | 4 ++-- .github/workflows/regular-checks-samples.yml | 2 +- Directory.Build.props | 4 ++-- samples/Directory.Build.props | 4 ++-- .../Mouseless.EventScheduler.Application.csproj | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index aa9fc8d73..d669710cd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -67,7 +67,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8 + dotnet-version: 9 - name: Pack run: | dotnet pack -o "packages" -c Release @@ -109,7 +109,7 @@ jobs: with: node-version: 22 - name: Disable AppArmour - run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: Build Docs run: | cd docs/.theme/ diff --git a/.github/workflows/regular-checks-docs.yml b/.github/workflows/regular-checks-docs.yml index cd3f0e080..e68777fcc 100644 --- a/.github/workflows/regular-checks-docs.yml +++ b/.github/workflows/regular-checks-docs.yml @@ -19,7 +19,7 @@ jobs: with: node-version: 22 - name: Disable AppArmour - run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns + run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns - name: Generate run: | cd docs/.theme/ diff --git a/.github/workflows/regular-checks-project.yml b/.github/workflows/regular-checks-project.yml index b8c3ba71a..9eb342e6c 100644 --- a/.github/workflows/regular-checks-project.yml +++ b/.github/workflows/regular-checks-project.yml @@ -44,7 +44,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8 + dotnet-version: 9 - name: Restore Dependencies run: dotnet restore - name: Format Solution @@ -63,7 +63,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8 + dotnet-version: 9 - name: Test if: ${{ matrix.os != 'ubuntu-latest' }} run: dotnet test -c Release diff --git a/.github/workflows/regular-checks-samples.yml b/.github/workflows/regular-checks-samples.yml index e1198b62b..636a8480d 100644 --- a/.github/workflows/regular-checks-samples.yml +++ b/.github/workflows/regular-checks-samples.yml @@ -32,7 +32,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8 + dotnet-version: 9 - name: samples/event-scheduler working-directory: samples/event-scheduler run: | diff --git a/Directory.Build.props b/Directory.Build.props index e2098f5b9..bf92fb2b9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,8 @@ - net8.0 - 12.0 + net9.0 + 13.0 true enable enable diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index 735d20146..78ae03efc 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -1,8 +1,8 @@ - net8.0 - 12.0 + net9.0 + 13.0 true enable enable diff --git a/samples/event-scheduler/src/Mouseless.EventScheduler.Application/Mouseless.EventScheduler.Application.csproj b/samples/event-scheduler/src/Mouseless.EventScheduler.Application/Mouseless.EventScheduler.Application.csproj index baff9e632..028f6a253 100644 --- a/samples/event-scheduler/src/Mouseless.EventScheduler.Application/Mouseless.EventScheduler.Application.csproj +++ b/samples/event-scheduler/src/Mouseless.EventScheduler.Application/Mouseless.EventScheduler.Application.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 enable enable From b2cd5d5b06a40486841c69ab9d1e933c9e6bc86f Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Fri, 31 Jan 2025 11:36:16 +0300 Subject: [PATCH 02/17] upgrade libraries --- Directory.Packages.props | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 71ed587f4..6d063c07d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,36 +6,36 @@ - + - + - - + + - - - - - - - - - + + + + + + + + + - + - - + + - - + + - - + + \ No newline at end of file From e72481d6bc62da8215eea620bba8c95f8bbab197 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Fri, 31 Jan 2025 18:22:52 +0300 Subject: [PATCH 03/17] upgrade dotnet version in dockerfile --- test/recipe/Baked.Test.Recipe.Service.Application/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/recipe/Baked.Test.Recipe.Service.Application/Dockerfile b/test/recipe/Baked.Test.Recipe.Service.Application/Dockerfile index 58c478529..379062e54 100644 --- a/test/recipe/Baked.Test.Recipe.Service.Application/Dockerfile +++ b/test/recipe/Baked.Test.Recipe.Service.Application/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1.7-labs ARG ENVIRONMENT Production -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base ARG ENVIRONMENT @@ -9,7 +9,7 @@ EXPOSE 80 ENV ASPNETCORE_ENVIRONMENT $ENVIRONMENT ENV ASPNETCORE_URLS=http://+:80 -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS publish +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS publish ARG ENVIRONMENT From 4bd45a16605382ef825faa01d4f4ef13cf3ad6bd Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Sat, 1 Feb 2025 12:41:24 +0300 Subject: [PATCH 04/17] set asp_env as default instead of string empty --- .../Testing/WebApplicationNfr.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/recipe/Baked.Recipe.Service.Application/Testing/WebApplicationNfr.cs b/src/recipe/Baked.Recipe.Service.Application/Testing/WebApplicationNfr.cs index 9749e18d5..504e194dd 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Testing/WebApplicationNfr.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Testing/WebApplicationNfr.cs @@ -48,6 +48,6 @@ public override void TearDown() { base.TearDown(); - Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", string.Empty); + Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", default); } } \ No newline at end of file From 0a3e3747dc7c44e2c32572384553e939dcbafced Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Sat, 1 Feb 2025 13:27:56 +0300 Subject: [PATCH 05/17] remove uncessary package --- Directory.Packages.props | 2 -- 1 file changed, 2 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6d063c07d..a823f8777 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,10 +10,8 @@ - - From 218f16ed011d1f433e7d15d8181173b40db4e463 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Sat, 1 Feb 2025 17:14:45 +0300 Subject: [PATCH 06/17] use collection exp. and fix linq --- .../DomainModelGenerator.cs | 4 ++-- src/core/Baked.Architecture/Architecture/Application.cs | 2 +- .../CodeGeneration/CodeGenerationExtensions.cs | 4 ++-- .../Communication/Mock/MockCommunicationExtensions.cs | 2 +- .../Cors/AspNetCore/AspNetCoreCorsExtensions.cs | 2 +- .../Domain/Model/TypeModelGenerics.cs | 2 +- .../Reporting/Fake/ReportContext.cs | 2 +- .../Reporting/NativeSql/ReportContext.cs | 2 +- .../RestApi/Model/ActionModel.cs | 2 +- .../Baked.Test.Recipe.Service/Reporting/ReportSamples.cs | 5 ++--- 10 files changed, 13 insertions(+), 14 deletions(-) diff --git a/research/domain-model-over-reflection/DomainModelOverReflection.Generator/DomainModelGenerator.cs b/research/domain-model-over-reflection/DomainModelOverReflection.Generator/DomainModelGenerator.cs index 28363326f..3ba8aba04 100644 --- a/research/domain-model-over-reflection/DomainModelOverReflection.Generator/DomainModelGenerator.cs +++ b/research/domain-model-over-reflection/DomainModelOverReflection.Generator/DomainModelGenerator.cs @@ -42,10 +42,10 @@ private void Execute(SourceProductionContext spc, Compilation compilation, Immut using DomainModelOverReflection.Models.Domain; namespace {{compilation.AssemblyName}}; - + public class DomainModelWithGeneration : IDomainModel { - static TypeModel[] _typeModels = new TypeModel[{{counter}}] + static TypeModel[] _typeModels = new TypeModel[{{counter}}] { {{builder}} }; diff --git a/src/core/Baked.Architecture/Architecture/Application.cs b/src/core/Baked.Architecture/Architecture/Application.cs index b91ea1a6c..455549f22 100644 --- a/src/core/Baked.Architecture/Architecture/Application.cs +++ b/src/core/Baked.Architecture/Architecture/Application.cs @@ -91,7 +91,7 @@ void ExecutePhases(List phases, ApplicationContext context) Apply(phase, context); } - phases = phases.Except(phasesOfThisIteration).ToList(); + phases = [.. phases.Except(phasesOfThisIteration)]; } } diff --git a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs index f808939e4..f2290a8b5 100644 --- a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs @@ -70,7 +70,7 @@ public static void Add(this IGeneratedAssemblyCollection generatedAssemblies, st public static GeneratedAssemblyDescriptor AddCode(this GeneratedAssemblyDescriptor descriptor, string code) => descriptor.AddCodes(code); public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, ICodeTemplate codeTemplate) => descriptor.AddCodes(codeTemplate.Render()); - public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, IEnumerable codes) => descriptor.AddCodes(codes.ToArray()); + public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, IEnumerable codes) => descriptor.AddCodes([.. codes]); public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, params string[] codes) { descriptor.Codes.AddRange(codes); @@ -81,7 +81,7 @@ public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescrip public static GeneratedAssemblyDescriptor AddReferenceFrom(this GeneratedAssemblyDescriptor descriptor) => descriptor.AddReferenceFrom(typeof(T)); public static GeneratedAssemblyDescriptor AddReferenceFrom(this GeneratedAssemblyDescriptor descriptor, Type type) => descriptor.AddReference(type.Assembly); public static GeneratedAssemblyDescriptor AddReference(this GeneratedAssemblyDescriptor descriptor, Assembly reference) => descriptor.AddReferences(reference); - public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, IEnumerable references) => descriptor.AddReferences(references.ToArray()); + public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, IEnumerable references) => descriptor.AddReferences([.. references]); public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, params Assembly[] references) { descriptor.References.AddRange(references); diff --git a/src/recipe/Baked.Recipe.Service.Application/Communication/Mock/MockCommunicationExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/Communication/Mock/MockCommunicationExtensions.cs index 8e86f076c..cc7ad7a58 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Communication/Mock/MockCommunicationExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Communication/Mock/MockCommunicationExtensions.cs @@ -49,7 +49,7 @@ public static IClient TheClient(this Mocker mockMe, } else if (responses is not null) { - setup().ReturnsAsync(responses.Select(r => new Response(statusCode ?? HttpStatusCode.OK, r.ToJsonString())).ToArray()); + setup().ReturnsAsync([.. responses.Select(r => new Response(statusCode ?? HttpStatusCode.OK, r.ToJsonString()))]); } else if (noResponse == true) { diff --git a/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs index 4551fd3e0..f0c34dc11 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs @@ -15,7 +15,7 @@ public static AspNetCoreCorsFeature AspNetCore(this CorsConfigurator configurato configurator.AspNetCore( options => options .AddPolicy("allow-origin", policy => policy - .WithOrigins(origins.Select(o => o.GetValue()).ToArray()) + .WithOrigins([.. origins.Select(o => o.GetValue())]) .AllowAnyHeader() .AllowAnyMethod() ), diff --git a/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelGenerics.cs b/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelGenerics.cs index 145b76dc9..3adcdb2f4 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelGenerics.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelGenerics.cs @@ -25,7 +25,7 @@ protected override void Fill(TypeModel result, Type type, DomainModelBuilder bui if (type.IsGenericType) { - generics.GenericTypeArguments = new(type.GenericTypeArguments.Select(builder.GetReference)); + generics.GenericTypeArguments = [.. type.GenericTypeArguments.Select(builder.GetReference)]; generics.GenericTypeDefinitionReference = !type.IsGenericTypeDefinition ? builder.GetReference(type.GetGenericTypeDefinition()) : default; } else diff --git a/src/recipe/Baked.Recipe.Service.Application/Reporting/Fake/ReportContext.cs b/src/recipe/Baked.Recipe.Service.Application/Reporting/Fake/ReportContext.cs index b12fc7052..b16b79e42 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Reporting/Fake/ReportContext.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Reporting/Fake/ReportContext.cs @@ -17,6 +17,6 @@ public class ReportContext(IFileProvider _fileProvider, ReportOptions _options) var match = fakes.FirstOrDefault(fake => fake.Matches(parameters)); if (match is null) { return []; } - return match.Result.Select(row => row.Values.ToArray()).ToArray(); + return [.. match.Result.Select(row => row.Values.ToArray())]; } } \ No newline at end of file diff --git a/src/recipe/Baked.Recipe.Service.Application/Reporting/NativeSql/ReportContext.cs b/src/recipe/Baked.Recipe.Service.Application/Reporting/NativeSql/ReportContext.cs index 9acfb2c53..3b742f4bc 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Reporting/NativeSql/ReportContext.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Reporting/NativeSql/ReportContext.cs @@ -22,6 +22,6 @@ public class ReportContext(IFileProvider _fileProvider, Func().ToArray(); + return [.. result.Cast()]; } } \ No newline at end of file diff --git a/src/recipe/Baked.Recipe.Service.Application/RestApi/Model/ActionModel.cs b/src/recipe/Baked.Recipe.Service.Application/RestApi/Model/ActionModel.cs index 108832ca4..bc8390195 100644 --- a/src/recipe/Baked.Recipe.Service.Application/RestApi/Model/ActionModel.cs +++ b/src/recipe/Baked.Recipe.Service.Application/RestApi/Model/ActionModel.cs @@ -30,7 +30,7 @@ public record ActionModel( public IEnumerable Parameters { get => Parameter.Values; init => Parameter = value.ToDictionary(p => p.Id); } - IEnumerable ActionParameters => Parameters.Where(p => !p.IsHardCoded).OrderBy(p => p.Order).OrderBy(p => p.IsOptional ? 1 : -1); + IEnumerable ActionParameters => Parameters.Where(p => !p.IsHardCoded).OrderBy(p => p.Order).ThenBy(p => p.IsOptional ? 1 : -1); IEnumerable RouteParameters => Parameters.Where(p => p.From == ParameterModelFrom.Route).OrderBy(p => p.RoutePosition); IEnumerable NonServiceParameters => ActionParameters.Where(p => p.From != ParameterModelFrom.Services); diff --git a/test/recipe/Baked.Test.Recipe.Service/Reporting/ReportSamples.cs b/test/recipe/Baked.Test.Recipe.Service/Reporting/ReportSamples.cs index edbe859c6..2fc8ab572 100644 --- a/test/recipe/Baked.Test.Recipe.Service/Reporting/ReportSamples.cs +++ b/test/recipe/Baked.Test.Recipe.Service/Reporting/ReportSamples.cs @@ -5,7 +5,7 @@ namespace Baked.Test.Reporting; public class ReportSamples(IReportContext _context) { public async Task> GetEntity(string @string) => - (await _context.Execute("entity", + [.. (await _context.Execute("entity", new() { { nameof(@string), $"{@string}%" } @@ -16,8 +16,7 @@ public async Task> GetEntity(string @string) => Convert.ToInt32(row[0]), (string?)row[1] ?? string.Empty ) - ) - .ToList(); + )]; public async Task GetNonExisting() { From b8a2020b713a82a98001b42952481b9bf23f8148 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Sat, 1 Feb 2025 18:36:09 +0300 Subject: [PATCH 07/17] replace method to property(GeneratedRegex) --- .../DomainAssembliesBusinessFeature.cs | 8 ++++---- .../AddRemoveChild/AddRemoveChildCodingStyleFeature.cs | 2 +- .../SingleByUnique/SingleByUniqueCodingStyleFeature.cs | 4 ++-- .../Baked.Recipe.Service.Application/Core/Regexes.cs | 4 ++-- .../Orm/AutoMap/AutoMapOrmFeature.cs | 2 +- .../Orm/AutoMap/Regexes.cs | 4 ++-- .../RestApi/Regexes.cs | 10 +++++----- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs index 494be1440..641cb99d3 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs @@ -244,10 +244,10 @@ c.Method.DefaultOverload.BaseDefinition.DeclaringType is not null && configurator.Context.Add(new TagDescriptions()); conventions.Add(new AutoHttpMethodConvention([ - (Regexes.StartsWithGet(), HttpMethod.Get), - (Regexes.IsUpdateChangeOrSet(), HttpMethod.Put), - (Regexes.StartsWithUpdateChangeOrSet(), HttpMethod.Patch), - (Regexes.StartsWithDeleteRemoveOrClear(), HttpMethod.Delete) + (Regexes.StartsWithGet, HttpMethod.Get), + (Regexes.IsUpdateChangeOrSet, HttpMethod.Put), + (Regexes.StartsWithUpdateChangeOrSet, HttpMethod.Patch), + (Regexes.StartsWithDeleteRemoveOrClear, HttpMethod.Delete) ])); conventions.Add(new GetAndDeleteAcceptsOnlyQueryConvention()); conventions.Add(new RemoveFromRouteConvention(["Get"])); diff --git a/src/recipe/Baked.Recipe.Service.Application/CodingStyle/AddRemoveChild/AddRemoveChildCodingStyleFeature.cs b/src/recipe/Baked.Recipe.Service.Application/CodingStyle/AddRemoveChild/AddRemoveChildCodingStyleFeature.cs index 868ac5014..058ffbf13 100644 --- a/src/recipe/Baked.Recipe.Service.Application/CodingStyle/AddRemoveChild/AddRemoveChildCodingStyleFeature.cs +++ b/src/recipe/Baked.Recipe.Service.Application/CodingStyle/AddRemoveChild/AddRemoveChildCodingStyleFeature.cs @@ -12,7 +12,7 @@ public void Configure(LayerConfigurator configurator) { conventions.Add(new PluralizeActionConvention(_when: c => (c.Action.Method == HttpMethod.Delete && c.Action.RouteParts.Count >= 2) || - (c.Action.Method == HttpMethod.Post && Regexes.StartsWithAddOrCreate().IsMatch(c.Action.Name) && c.Action.RouteParts.Count >= 2) + (c.Action.Method == HttpMethod.Post && Regexes.StartsWithAddOrCreate.IsMatch(c.Action.Name) && c.Action.RouteParts.Count >= 2) )); conventions.Add(new OnlyEntityParameterIsInRouteForDeleteChildConvention()); conventions.Add(new RemoveFromRouteConvention(["Add", "Create"])); diff --git a/src/recipe/Baked.Recipe.Service.Application/CodingStyle/SingleByUnique/SingleByUniqueCodingStyleFeature.cs b/src/recipe/Baked.Recipe.Service.Application/CodingStyle/SingleByUnique/SingleByUniqueCodingStyleFeature.cs index 68e82fa92..0e1ddc5d1 100644 --- a/src/recipe/Baked.Recipe.Service.Application/CodingStyle/SingleByUnique/SingleByUniqueCodingStyleFeature.cs +++ b/src/recipe/Baked.Recipe.Service.Application/CodingStyle/SingleByUnique/SingleByUniqueCodingStyleFeature.cs @@ -18,7 +18,7 @@ public void Configure(LayerConfigurator configurator) builder.Conventions.AddMethodMetadata( apply: (c, add) => { - var match = Regexes.StartsWithSingleBy().Match(c.Method.Name); + var match = Regexes.StartsWithSingleBy.Match(c.Method.Name); var propertyName = match.Groups["Name"].Value; var propertyType = c.Method.DefaultOverload.Parameters[propertyName.Camelize()].ParameterType; if (propertyType.Is() || propertyType.IsEnum) @@ -31,7 +31,7 @@ public void Configure(LayerConfigurator configurator) }, when: c => c.Type.Has() && - Regexes.StartsWithSingleBy().IsMatch(c.Method.Name) + Regexes.StartsWithSingleBy.IsMatch(c.Method.Name) ); }); diff --git a/src/recipe/Baked.Recipe.Service.Application/Core/Regexes.cs b/src/recipe/Baked.Recipe.Service.Application/Core/Regexes.cs index a6c6147c6..117d80121 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Core/Regexes.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Core/Regexes.cs @@ -6,10 +6,10 @@ namespace Baked.Core; internal static partial class Regexes { [GeneratedRegex(@"[\s\S]*?(?=.Application|$)")] - public static partial Regex AssemblyNameBeforeApplicationSuffix(); + public static partial Regex AssemblyNameBeforeApplicationSuffix { get; } public static string GetNameBeforeApplicationSuffix(this Assembly assembly) => - AssemblyNameBeforeApplicationSuffix() + AssemblyNameBeforeApplicationSuffix .Match(assembly.FullName ?? string.Empty) .Value; } \ No newline at end of file diff --git a/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/AutoMapOrmFeature.cs b/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/AutoMapOrmFeature.cs index 12105bff1..83345dfeb 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/AutoMapOrmFeature.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/AutoMapOrmFeature.cs @@ -145,7 +145,7 @@ public void Configure(LayerConfigurator configurator) { var domainModel = configurator.Context.GetDomainModel(); - conventions.Add(new AutoHttpMethodConvention([(Regexes.StartsWithFirstBySingleByOrBy(), HttpMethod.Get)]), order: -10); + conventions.Add(new AutoHttpMethodConvention([(Regexes.StartsWithFirstBySingleByOrBy, HttpMethod.Get)]), order: -10); conventions.Add(new LookupEntityByIdConvention(domainModel)); conventions.Add(new LookupEntitiesByIdsConvention(domainModel)); conventions.Add(new RemoveFromRouteConvention(["FirstBy", "SingleBy", "By"], diff --git a/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/Regexes.cs b/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/Regexes.cs index 311807aa3..991a09a17 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/Regexes.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Orm/AutoMap/Regexes.cs @@ -5,8 +5,8 @@ namespace Baked.Orm.AutoMap; internal static partial class Regexes { [GeneratedRegex(@"^(FirstBy|SingleBy|By).*$", RegexOptions.None, "en-US")] - public static partial Regex StartsWithFirstBySingleByOrBy(); + public static partial Regex StartsWithFirstBySingleByOrBy { get; } [GeneratedRegex(@"^SingleBy(?.+)$", RegexOptions.None, "en-US")] - public static partial Regex StartsWithSingleBy(); + public static partial Regex StartsWithSingleBy { get; } } \ No newline at end of file diff --git a/src/recipe/Baked.Recipe.Service.Application/RestApi/Regexes.cs b/src/recipe/Baked.Recipe.Service.Application/RestApi/Regexes.cs index 1151544ec..4a1ea7ba6 100644 --- a/src/recipe/Baked.Recipe.Service.Application/RestApi/Regexes.cs +++ b/src/recipe/Baked.Recipe.Service.Application/RestApi/Regexes.cs @@ -5,17 +5,17 @@ namespace Baked.RestApi; internal static partial class Regexes { [GeneratedRegex(@"^Get.*$", RegexOptions.None, "en-US")] - public static partial Regex StartsWithGet(); + public static partial Regex StartsWithGet { get; } [GeneratedRegex(@"^(Add|Create).*$", RegexOptions.None, "en-US")] - public static partial Regex StartsWithAddOrCreate(); + public static partial Regex StartsWithAddOrCreate { get; } [GeneratedRegex(@"^(Delete|Remove|Clear).*$", RegexOptions.None, "en-US")] - public static partial Regex StartsWithDeleteRemoveOrClear(); + public static partial Regex StartsWithDeleteRemoveOrClear { get; } [GeneratedRegex(@"^(Update|Change|Set)$", RegexOptions.None, "en-US")] - public static partial Regex IsUpdateChangeOrSet(); + public static partial Regex IsUpdateChangeOrSet { get; } [GeneratedRegex(@"^(Update|Change|Set).*$", RegexOptions.None, "en-US")] - public static partial Regex StartsWithUpdateChangeOrSet(); + public static partial Regex StartsWithUpdateChangeOrSet { get; } } \ No newline at end of file From 17d0be83955c835d0eba38ede08e2819862686a4 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Sun, 2 Feb 2025 16:33:34 +0300 Subject: [PATCH 08/17] add migration document --- unreleased.md | 82 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/unreleased.md b/unreleased.md index 8110e1553..c468b073e 100644 --- a/unreleased.md +++ b/unreleased.md @@ -1,13 +1,47 @@ # Unreleased +## .NET Upgrade + +Baked now supports .NET 9! Below you can find a task list to upgrade your +projects. + +```markdown +- [ ] Upgrade .NET and C# versions + - [ ] in projects + - [ ] in docker files + - [ ] in GitHub workflows +- [ ] Upgrade Baked version +- [ ] You can use `GeneratedRegex`es in properties instead of methods +- [ ] If `Base64` encoded information is carried in the url, use `Base64Url`. + - [ ] If need to take parameters with an `Array` using params + and then convert to `IEnumerable` type, use `IEnumerable` instead of `Array`. +- [ ] Use the new linQ extensions(`CountBy`, `AggregateBy`, + `Index(IEnumerable))`. +- [ ] Use new `TimeSpan.From*` overloads + - `FromDays` + - `FromHours` + - `FromMinutes` + - `FromSeconds` + - `FromMilliseconds` + - `FromMicroseconds` +- [ ] Use Keyed Services in Middlewares. +``` + +### Upgrade .NET and C# versions + +- Upgrade the project's `C#` language to `13`. +- Framework version upgrade to `net9.0` in the projects. +- Framework and sdk version upgrade to `9` in `Dockerfile`. +- Upgrade dotnet version `9` in Github actions. + ## Features -- `Application` now provies `Bake` and `Start` modes which can be run both +- `Application` now provies `Bake` and `Start` modes which can be run both together or individually with distinct `ApplicationContext`'s. - `RunFlags` is introduced for configuring application mode - `LayerBase` now provies `GetBakePhases()` method to enable registering - specific phases to run at `Bake` mode -- `Service` and `Data Source` recipies now triggers `Bake` mode run at post + specific phases to run at `Bake` mode +- `Service` and `Data Source` recipies now triggers `Bake` mode run at post build - `Domain` layer's `AddDomainTypes` and `BuildDomainModel` phases now only runs in `Bake` mode @@ -20,22 +54,46 @@ ## Improvements -- `CodeGeneration` layer now compiles and saves generated assemblies and files +- `CodeGeneration` layer now compiles and saves generated assemblies and files to entry assembly location with `ASPNETCORE_ENVIRONMENT` subfolder - `DomainAssemblies` feature now generates - `ICasterConfigurer` - implementations and + implementations and - `TagDescriptor` - `RequestResponseExample` - json files in `Bake` mode -- Following features now generates `IServiceAdder` implementations from - `DomainModel` in `Bake` mode + json files in `Bake` mode +- Following features now generates `IServiceAdder` implementations from + `DomainModel` in `Bake` mode - `Transient` - `Scoped` - `Singleton` - `AutoMapOrm` - `ProblemDetails` -- `GiveMe.PropertyOf` helper is renamed to `ThePropertyOf` -- `GiveMe.MethodOf` helper is renamed to `TheMethodOf` - - \ No newline at end of file +- `GiveMe.PropertyOf` helper is renamed to `ThePropertyOf` +- `GiveMe.MethodOf` helper is renamed to `TheMethodOf` + +## Library Upgrades + +| Package | Old Version | New Version | +| ----------------------------------------------- | ----------- | ----------- | +| coverlet.collector | 6.0.2 | 6.0.4 | +| Microsoft.AspNetCore.Mvc.NewtonsoftJson | 8.0.8 | 9.0.1 | +| Microsoft.AspNetCore.Mvc.Testing | 8.0.10 | 9.0.1 | +| Microsoft.AspNetCore.Authorization | 8.0.8 | removed | +| Microsoft.CodeAnalysis.CSharp | 4.11.0 | 4.12.0 | +| Microsoft.CodeAnalysis.Analyzers | 3.3.4 | removed | +| Microsoft.Extensions.Caching.Abstraction | 8.0.0 | 9.0.1 | +| Microsoft.Extensions.Configuration.Abstractions | 8.0.0 | 9.0.1 | +| Microsoft.Extensions.Configuration.Binder | 8.0.2 | 9.0.1 | +| Microsoft.Extensions.FileProviders.Abstractions | 8.0.0 | 9.0.1 | +| Microsoft.Extensions.Logging.Abstractions | 8.0.2 | 9.0.1 | +| Microsoft.Extensions.TimeProvider.Testing | 8.10.0 | 9.1.0 | +| Microsoft.NET.Test.Sdk | 17.11.1 | 17.12.0 | +| MySql.Data | 9.1.0 | 9.2.0 | +| NHibernate.Extensions.Sqlite | 8.0.14 | 9.0.0 | +| NUnit | 4.2.2 | 4.3.2 | +| Npgsql | 8.0.5 | 9.0.2 | +| Oracle.ManagedDataAccess.Core | 23.6.0 | 23.7.0 | +| Shouldly | 4.2.1 | 4.3.0 | +| Swashbuckle.AspNetCore | 6.9.0 | 7.2.0 | +| Swashbuckle.AspNetCore.Annotations | 6.9.0 | 7.2.0 | From eacc0f3066361cc27fa2e56b267d96bce58e6298 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 11:53:45 +0300 Subject: [PATCH 09/17] change schema id --- .../DomainAssembliesBusinessFeature.cs | 16 ++------- .../SwashbuckleSchemaHelper.cs | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwashbuckleSchemaHelper.cs diff --git a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs index 641cb99d3..a9055a074 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs @@ -6,7 +6,7 @@ using Baked.RestApi; using Baked.RestApi.Conventions; using Baked.RestApi.Model; -using Humanizer; +// using Humanizer; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using System.Reflection; @@ -278,19 +278,9 @@ c.Method.DefaultOverload.BaseDefinition.DeclaringType is not null && } swaggerGenOptions.EnableAnnotations(); - swaggerGenOptions.CustomSchemaIds(t => - { - string[] splitedNamespace = t.Namespace?.Split(".") ?? []; - string name = t.IsNested && t.FullName is not null - ? t.FullName.Replace($"{t.Namespace}.", string.Empty).Replace("+", "_") - : t.Name; - - var result = splitedNamespace.Length > 1 - ? $"{splitedNamespace.Skip(1).Join('_')}_{name}" - : name; - return result.Replace("_", "--").Kebaberize(); - }); + var schemaHelper = new SwashbuckleSchemaHelper(); + swaggerGenOptions.CustomSchemaIds(type => schemaHelper.GetSchemaId(type)); swaggerGenOptions.OrderActionsBy(apiDescription => { diff --git a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwashbuckleSchemaHelper.cs b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwashbuckleSchemaHelper.cs new file mode 100644 index 000000000..c3a958850 --- /dev/null +++ b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwashbuckleSchemaHelper.cs @@ -0,0 +1,34 @@ +namespace Baked.Business.DomainAssemblies; + +public class SwashbuckleSchemaHelper +{ + private readonly Dictionary> _schemaNameRepetition = new(); + + private string DefaultSchemaIdSelector(Type modelType) + { + if (!modelType.IsConstructedGenericType) return modelType.Name.Replace("[]", "Array"); + + var prefix = modelType.GetGenericArguments() + .Select(genericArg => DefaultSchemaIdSelector(genericArg)) + .Aggregate((previous, current) => previous + current); + + return prefix + modelType.Name.Split('`').First(); + } + + public string GetSchemaId(Type modelType) + { + string id = DefaultSchemaIdSelector(modelType); + + if (!_schemaNameRepetition.ContainsKey(id)) + _schemaNameRepetition.Add(id, new List()); + + var modelNameList = _schemaNameRepetition[id]; + var fullName = modelType.FullName ?? string.Empty; + if (!string.IsNullOrEmpty(fullName) && !modelNameList.Contains(fullName)) + modelNameList.Add(fullName); + + int index = modelNameList.IndexOf(fullName); + + return $"{id}{(index >= 1 ? index.ToString() : string.Empty)}"; + } +} \ No newline at end of file From 246e74095ba011e7151735ac1f2515b100b864d7 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 11:57:51 +0300 Subject: [PATCH 10/17] update release note --- unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/unreleased.md b/unreleased.md index c468b073e..961e7e0bf 100644 --- a/unreleased.md +++ b/unreleased.md @@ -71,6 +71,7 @@ projects. - `ProblemDetails` - `GiveMe.PropertyOf` helper is renamed to `ThePropertyOf` - `GiveMe.MethodOf` helper is renamed to `TheMethodOf` +- Removed namespaces from `SchemaId` created in Swagger. ## Library Upgrades From 0844d11069c6bf159a1e12fc4a5911551e8a5138 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 12:09:58 +0300 Subject: [PATCH 11/17] fix swagger test --- .../Business/SwaggerSchemaGeneration.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/recipe/Baked.Test.Recipe.Service.Test/Business/SwaggerSchemaGeneration.cs b/test/recipe/Baked.Test.Recipe.Service.Test/Business/SwaggerSchemaGeneration.cs index 88c59f17b..205f4176d 100644 --- a/test/recipe/Baked.Test.Recipe.Service.Test/Business/SwaggerSchemaGeneration.cs +++ b/test/recipe/Baked.Test.Recipe.Service.Test/Business/SwaggerSchemaGeneration.cs @@ -88,21 +88,21 @@ public async Task Method_parameter_comments_are_placed_in_schema_property_descri var response = await Client.GetAsync("/swagger/samples/swagger.json"); dynamic? content = await response.Content.Deserialize(); - var schema = content?.components.schemas["test--business--documentation-samples--method-request"]; + var schema = content?.components.schemas["MethodRequest"]; ((string?)schema?.properties["parameter1"].description).ShouldBe("Parameter 1 documentation"); ((string?)schema?.properties["parameter2"].description).ShouldBe("Parameter 2 documentation"); } - [TestCase("entity-parameters", "entityId", "Entity description")] - [TestCase("entity-list-parameters", "entityIds", "Entities description")] - [TestCase("entity-list-parameters", "otherEntityIds", "Other entities description")] + [TestCase("EntityParameters", "entityId", "Entity description")] + [TestCase("EntityListParameters", "entityIds", "Entities description")] + [TestCase("EntityListParameters", "otherEntityIds", "Other entities description")] public async Task Entity_parameter_comments_are_kept_even_if_their_name_change(string method, string parameter, string expected) { var response = await Client.GetAsync("/swagger/samples/swagger.json"); dynamic? content = await response.Content.Deserialize(); - var schema = content?.components.schemas[$"test--business--method-samples--{method}-request"]; + var schema = content?.components.schemas[$"{method}Request"]; ((string?)schema?.properties[parameter].description).ShouldBe(expected); } @@ -147,7 +147,7 @@ public async Task Documented_properties_are_included_in_schema_property_descript var response = await Client.GetAsync("/swagger/samples/swagger.json"); dynamic? content = await response.Content.Deserialize(); - var schema = content?.components.schemas["test--business--documented-data"]; + var schema = content?.components.schemas["DocumentedData"]; ((string?)schema?.description).ShouldBe("Data summary"); ((string?)schema?.properties["property"].description).ShouldBe("Property summary"); From 7b68c73a2510fd58212330a687dc0935ecc2066a Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 13:19:12 +0300 Subject: [PATCH 12/17] rename swaggerhelper --- .../DomainAssemblies/DomainAssembliesBusinessFeature.cs | 3 +-- .../{SwashbuckleSchemaHelper.cs => SwaggerSchemaHelper.cs} | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) rename src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/{SwashbuckleSchemaHelper.cs => SwaggerSchemaHelper.cs} (96%) diff --git a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs index a9055a074..070068875 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs @@ -6,7 +6,6 @@ using Baked.RestApi; using Baked.RestApi.Conventions; using Baked.RestApi.Model; -// using Humanizer; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using System.Reflection; @@ -279,7 +278,7 @@ c.Method.DefaultOverload.BaseDefinition.DeclaringType is not null && swaggerGenOptions.EnableAnnotations(); - var schemaHelper = new SwashbuckleSchemaHelper(); + var schemaHelper = new SwaggerSchemaHelper(); swaggerGenOptions.CustomSchemaIds(type => schemaHelper.GetSchemaId(type)); swaggerGenOptions.OrderActionsBy(apiDescription => diff --git a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwashbuckleSchemaHelper.cs b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwaggerSchemaHelper.cs similarity index 96% rename from src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwashbuckleSchemaHelper.cs rename to src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwaggerSchemaHelper.cs index c3a958850..f6da7a2fe 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwashbuckleSchemaHelper.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwaggerSchemaHelper.cs @@ -1,6 +1,6 @@ namespace Baked.Business.DomainAssemblies; -public class SwashbuckleSchemaHelper +public class SwaggerSchemaHelper { private readonly Dictionary> _schemaNameRepetition = new(); From 4d3897795f47962a44a7be68c4da6a893dfc236f Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 15:33:58 +0300 Subject: [PATCH 13/17] fix indent and use baked rule --- .../DomainAssembliesBusinessFeature.cs | 2 +- .../DomainAssemblies/SwaggerSchemaHelper.cs | 35 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs index 070068875..3f4ee210a 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/DomainAssembliesBusinessFeature.cs @@ -279,7 +279,7 @@ c.Method.DefaultOverload.BaseDefinition.DeclaringType is not null && swaggerGenOptions.EnableAnnotations(); var schemaHelper = new SwaggerSchemaHelper(); - swaggerGenOptions.CustomSchemaIds(type => schemaHelper.GetSchemaId(type)); + swaggerGenOptions.CustomSchemaIds(schemaHelper.GetSchemaId); swaggerGenOptions.OrderActionsBy(apiDescription => { diff --git a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwaggerSchemaHelper.cs b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwaggerSchemaHelper.cs index f6da7a2fe..547528df2 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwaggerSchemaHelper.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Business/DomainAssemblies/SwaggerSchemaHelper.cs @@ -2,33 +2,40 @@ namespace Baked.Business.DomainAssemblies; public class SwaggerSchemaHelper { - private readonly Dictionary> _schemaNameRepetition = new(); - - private string DefaultSchemaIdSelector(Type modelType) - { - if (!modelType.IsConstructedGenericType) return modelType.Name.Replace("[]", "Array"); - - var prefix = modelType.GetGenericArguments() - .Select(genericArg => DefaultSchemaIdSelector(genericArg)) - .Aggregate((previous, current) => previous + current); - - return prefix + modelType.Name.Split('`').First(); - } + readonly Dictionary> _schemaNameRepetition = []; public string GetSchemaId(Type modelType) { - string id = DefaultSchemaIdSelector(modelType); + var id = DefaultSchemaIdSelector(modelType); if (!_schemaNameRepetition.ContainsKey(id)) + { _schemaNameRepetition.Add(id, new List()); + } var modelNameList = _schemaNameRepetition[id]; var fullName = modelType.FullName ?? string.Empty; if (!string.IsNullOrEmpty(fullName) && !modelNameList.Contains(fullName)) + { modelNameList.Add(fullName); + } - int index = modelNameList.IndexOf(fullName); + var index = modelNameList.IndexOf(fullName); return $"{id}{(index >= 1 ? index.ToString() : string.Empty)}"; } + + string DefaultSchemaIdSelector(Type modelType) + { + if (!modelType.IsConstructedGenericType) + { + return modelType.Name.Replace("[]", "Array"); + } + + var prefix = modelType.GetGenericArguments() + .Select(DefaultSchemaIdSelector) + .Aggregate((previous, current) => previous + current); + + return prefix + modelType.Name.Split('`').First(); + } } \ No newline at end of file From 79812adb333b840328010817e7730210691989fc Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 16:00:27 +0300 Subject: [PATCH 14/17] combine same method --- .../CodeGeneration/CodeGenerationExtensions.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs index f2290a8b5..106be0db2 100644 --- a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs @@ -69,9 +69,8 @@ public static void Add(this IGeneratedAssemblyCollection generatedAssemblies, st } public static GeneratedAssemblyDescriptor AddCode(this GeneratedAssemblyDescriptor descriptor, string code) => descriptor.AddCodes(code); - public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, ICodeTemplate codeTemplate) => descriptor.AddCodes(codeTemplate.Render()); - public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, IEnumerable codes) => descriptor.AddCodes([.. codes]); - public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, params string[] codes) + public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, ICodeTemplate codeTemplate) => descriptor.AddCodes([.. codeTemplate.Render()]); + public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, params List codes) { descriptor.Codes.AddRange(codes); @@ -81,8 +80,7 @@ public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescrip public static GeneratedAssemblyDescriptor AddReferenceFrom(this GeneratedAssemblyDescriptor descriptor) => descriptor.AddReferenceFrom(typeof(T)); public static GeneratedAssemblyDescriptor AddReferenceFrom(this GeneratedAssemblyDescriptor descriptor, Type type) => descriptor.AddReference(type.Assembly); public static GeneratedAssemblyDescriptor AddReference(this GeneratedAssemblyDescriptor descriptor, Assembly reference) => descriptor.AddReferences(reference); - public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, IEnumerable references) => descriptor.AddReferences([.. references]); - public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, params Assembly[] references) + public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, params IEnumerable references) { descriptor.References.AddRange(references); From f12090ec496fbe7de6f9e0aad3ffd927bd56cfd5 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 16:07:23 +0300 Subject: [PATCH 15/17] use IEnumerable instead of list --- .../CodeGeneration/CodeGenerationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs index 106be0db2..f046193a0 100644 --- a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeGenerationExtensions.cs @@ -70,7 +70,7 @@ public static void Add(this IGeneratedAssemblyCollection generatedAssemblies, st public static GeneratedAssemblyDescriptor AddCode(this GeneratedAssemblyDescriptor descriptor, string code) => descriptor.AddCodes(code); public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, ICodeTemplate codeTemplate) => descriptor.AddCodes([.. codeTemplate.Render()]); - public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, params List codes) + public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescriptor descriptor, params IEnumerable codes) { descriptor.Codes.AddRange(codes); From 8beed840adb7426c474140c0fd05bd18f759d99a Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 16:09:13 +0300 Subject: [PATCH 16/17] update migration notes --- unreleased.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unreleased.md b/unreleased.md index 961e7e0bf..9787c0df7 100644 --- a/unreleased.md +++ b/unreleased.md @@ -13,8 +13,7 @@ projects. - [ ] Upgrade Baked version - [ ] You can use `GeneratedRegex`es in properties instead of methods - [ ] If `Base64` encoded information is carried in the url, use `Base64Url`. - - [ ] If need to take parameters with an `Array` using params - and then convert to `IEnumerable` type, use `IEnumerable` instead of `Array`. +- [ ] `params` arguments should be converted from arrays to `IEnumerable` - [ ] Use the new linQ extensions(`CountBy`, `AggregateBy`, `Index(IEnumerable))`. - [ ] Use new `TimeSpan.From*` overloads From e28e593f836294ff8f19b36021612342c2d16a52 Mon Sep 17 00:00:00 2001 From: Sefer Mirza Date: Mon, 3 Feb 2025 16:37:56 +0300 Subject: [PATCH 17/17] convert all arram type params to IEnumerable type --- .../Architecture/LayerConfigurator.cs | 6 +++--- .../CodeGeneration/CodeTemplateBase.cs | 2 +- .../Core/CoreExtensions.cs | 2 +- .../Cors/AspNetCore/AspNetCoreCorsExtensions.cs | 2 +- .../Domain/Model/TypeModel.cs | 2 +- .../Domain/Model/TypeModelReference.cs | 2 +- .../MockOverrider/MockOverriderExtensions.cs | 16 ++++++++-------- .../Testing/TestingExtensions.cs | 8 ++++---- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/core/Baked.Architecture/Architecture/LayerConfigurator.cs b/src/core/Baked.Architecture/Architecture/LayerConfigurator.cs index 3a8377676..101dfc1b2 100644 --- a/src/core/Baked.Architecture/Architecture/LayerConfigurator.cs +++ b/src/core/Baked.Architecture/Architecture/LayerConfigurator.cs @@ -37,7 +37,7 @@ record Target(Type Type, object Value); readonly ApplicationContext _context; readonly List _targets; - LayerConfigurator(ApplicationContext context, params Target[] targets) + LayerConfigurator(ApplicationContext context, params IEnumerable targets) { _context = context; _targets = [.. targets]; @@ -66,9 +66,9 @@ public void Configure(Action(0), ValueAs(1), ValueAs(2)); } - bool Matches(params Type[] types) + bool Matches(params IList types) { - if (_targets.Count != types.Length) { return false; } + if (_targets.Count != types.Count) { return false; } for (var i = 0; i < _targets.Count; i++) { diff --git a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeTemplateBase.cs b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeTemplateBase.cs index ddcab9e1d..3b7281ecf 100644 --- a/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeTemplateBase.cs +++ b/src/recipe/Baked.Recipe.Service.Application/CodeGeneration/CodeTemplateBase.cs @@ -4,7 +4,7 @@ public abstract class CodeTemplateBase : ICodeTemplate { protected abstract IEnumerable Render(); - protected string Join(string separator, params string[] statements) => + protected string Join(string separator, params IEnumerable statements) => statements .Where(s => !string.IsNullOrWhiteSpace(s)) .Join(separator ?? Environment.NewLine); diff --git a/src/recipe/Baked.Recipe.Service.Application/Core/CoreExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/Core/CoreExtensions.cs index 31785d30d..046ec3107 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Core/CoreExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Core/CoreExtensions.cs @@ -53,7 +53,7 @@ public static DateTime ADateTime(this Stubber _, ) => new(year, month, day, hour, minute, second); public static Dictionary ADictionary(this Stubber giveMe) => giveMe.ADictionary(); - public static Dictionary ADictionary(this Stubber _, params (TKey, TValue)[] pairs) + public static Dictionary ADictionary(this Stubber _, params IEnumerable<(TKey, TValue)> pairs) where TKey : notnull => pairs.ToDictionary(pair => pair.Item1, pair => pair.Item2); diff --git a/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs index f0c34dc11..116723e68 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Cors/AspNetCore/AspNetCoreCorsExtensions.cs @@ -11,7 +11,7 @@ public static class AspNetCoreCorsExtensions /// Returns 'AspNetCoreCors' feature with a single policy setup with given origins, /// any header and any method /// - public static AspNetCoreCorsFeature AspNetCore(this CorsConfigurator configurator, params Setting[] origins) => + public static AspNetCoreCorsFeature AspNetCore(this CorsConfigurator configurator, params IEnumerable> origins) => configurator.AspNetCore( options => options .AddPolicy("allow-origin", policy => policy diff --git a/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModel.cs b/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModel.cs index 59d8f5206..2c599f27b 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModel.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModel.cs @@ -82,7 +82,7 @@ public bool IsAssignableTo(Type type) => this.TryGetInheritance(out var inheritance) && (inheritance.BaseType?.IsAssignableTo(type) == true || inheritance.Interfaces.Contains(type)) ; - public string MakeGenericTypeId(params TypeModel[] typeArguments) => + public string MakeGenericTypeId(params IEnumerable typeArguments) => TypeModelReference.IdOf(this, typeArguments); public override bool Equals(object? obj) => diff --git a/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelReference.cs b/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelReference.cs index 03442a2bf..0c8fa1e8c 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelReference.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Domain/Model/TypeModelReference.cs @@ -8,7 +8,7 @@ internal static string IdFrom(Type type) => $"{type.Namespace}.{type.Name}<{type.GenericTypeArguments.Select(IdFrom).Join(',')}>" : type.FullName ?? type.Name; - internal static string IdOf(TypeModel typeDefinition, params TypeModel[] typeArguments) => + internal static string IdOf(TypeModel typeDefinition, params IEnumerable typeArguments) => $"{typeDefinition.Namespace}.{typeDefinition.Name}<{typeArguments.Select(t => t.CSharpFriendlyFullName).Join(',')}>"; internal TypeModelReference(Type type) : this(type, IdFrom(type)) { } diff --git a/src/recipe/Baked.Recipe.Service.Application/MockOverrider/MockOverriderExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/MockOverrider/MockOverriderExtensions.cs index 08594c973..2c3f302a7 100644 --- a/src/recipe/Baked.Recipe.Service.Application/MockOverrider/MockOverriderExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/MockOverrider/MockOverriderExtensions.cs @@ -10,28 +10,28 @@ public static class MockOverriderExtensions public static void AddMockOverrider(this List features, Func> configure) => features.Add(configure(new())); - public static T The(this Stubber giveMe, object? mockOverride, params object?[] otherMockOverrides) where T : notnull => + public static T The(this Stubber giveMe, object? mockOverride, params IEnumerable otherMockOverrides) where T : notnull => giveMe.TheServiceProvider().OverrideMocksAndGetRequiredService([mockOverride, .. otherMockOverrides]); - public static object The(this Stubber giveMe, Type type, object? mockOverride, params object?[] otherMockOverrides) => + public static object The(this Stubber giveMe, Type type, object? mockOverride, params IEnumerable otherMockOverrides) => giveMe.TheServiceProvider().OverrideMocksAndGetRequiredService(type, [mockOverride, .. otherMockOverrides]); - public static T An(this Stubber giveMe, object? mockOverride, params object?[] otherMockOverrides) where T : notnull => + public static T An(this Stubber giveMe, object? mockOverride, params IEnumerable otherMockOverrides) where T : notnull => giveMe.TheServiceProvider().OverrideMocksAndGetRequiredService([mockOverride, .. otherMockOverrides]); - public static object An(this Stubber giveMe, Type type, object? mockOverride, params object?[] otherMockOverrides) => + public static object An(this Stubber giveMe, Type type, object? mockOverride, params IEnumerable otherMockOverrides) => giveMe.TheServiceProvider().OverrideMocksAndGetRequiredService(type, [mockOverride, .. otherMockOverrides]); - public static T A(this Stubber giveMe, object? mockOverride, params object?[] otherMockOverrides) where T : notnull => + public static T A(this Stubber giveMe, object? mockOverride, params IEnumerable otherMockOverrides) where T : notnull => giveMe.TheServiceProvider().OverrideMocksAndGetRequiredService([mockOverride, .. otherMockOverrides]); - public static object A(this Stubber giveMe, Type type, params object?[] mockOverrides) => + public static object A(this Stubber giveMe, Type type, params IEnumerable mockOverrides) => giveMe.TheServiceProvider().OverrideMocksAndGetRequiredService(type, mockOverrides); - static T OverrideMocksAndGetRequiredService(this IServiceProvider serviceProvider, params object?[] mockOverrides) where T : notnull => + static T OverrideMocksAndGetRequiredService(this IServiceProvider serviceProvider, params IEnumerable mockOverrides) where T : notnull => (T)serviceProvider.OverrideMocksAndGetRequiredService(typeof(T), mockOverrides); - static object OverrideMocksAndGetRequiredService(this IServiceProvider serviceProvider, Type type, params object?[] mockOverrides) + static object OverrideMocksAndGetRequiredService(this IServiceProvider serviceProvider, Type type, params IEnumerable mockOverrides) { var overrider = serviceProvider.GetRequiredService(); diff --git a/src/recipe/Baked.Recipe.Service.Application/Testing/TestingExtensions.cs b/src/recipe/Baked.Recipe.Service.Application/Testing/TestingExtensions.cs index e3491474a..0fb5ec0b7 100644 --- a/src/recipe/Baked.Recipe.Service.Application/Testing/TestingExtensions.cs +++ b/src/recipe/Baked.Recipe.Service.Application/Testing/TestingExtensions.cs @@ -27,13 +27,13 @@ public static void Add(this IMockCollection mocks, Type service, bool singleton Setup: setup == default ? default : obj => setup(obj) )); - public static void Returns(this ISetup setup, params TResult[] results) where TMock : class + public static void Returns(this ISetup setup, params IList results) where TMock : class { int currentResultIndex = 0; setup.Returns(() => { - if (currentResultIndex >= results.Length) + if (currentResultIndex >= results.Count) { currentResultIndex = 0; } @@ -42,13 +42,13 @@ public static void Returns(this ISetup setup, pa }); } - public static void ReturnsAsync(this ISetup> setup, params TResult[] results) where TMock : class + public static void ReturnsAsync(this ISetup> setup, params IList results) where TMock : class { int currentResultIndex = 0; setup.ReturnsAsync(() => { - if (currentResultIndex >= results.Length) + if (currentResultIndex >= results.Count) { currentResultIndex = 0; }