Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue / .NET 9 Update #200

Merged
merged 17 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/regular-checks-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/regular-checks-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/regular-checks-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>13.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
42 changes: 20 additions & 22 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,34 @@

<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="FluentNHibernate" Version="3.4.0" />
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="23.6.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="8.0.8" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.10" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="8.0.10" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.10.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="23.7.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Abstractions" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.1.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MySql.Data" Version="9.1.0" />
<PackageVersion Include="MySql.Data" Version="9.2.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NHibernate" Version="5.5.2" />
<PackageVersion Include="NHibernate.Extensions.Sqlite" Version="8.0.14" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NHibernate.Extensions.Sqlite" Version="9.0.0" />
<PackageVersion Include="NUnit" Version="4.3.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="Npgsql" Version="8.0.5" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="Npgsql" Version="9.0.2" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.10" />
<PackageVersion Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.9.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
};
Expand Down
4 changes: 2 additions & 2 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>13.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Baked.Architecture/Architecture/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void ExecutePhases(List<IPhase> phases, ApplicationContext context)
Apply(phase, context);
}

phases = phases.Except(phasesOfThisIteration).ToList();
phases = [.. phases.Except(phasesOfThisIteration)];
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/Baked.Architecture/Architecture/LayerConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ record Target(Type Type, object Value);
readonly ApplicationContext _context;
readonly List<Target> _targets;

LayerConfigurator(ApplicationContext context, params Target[] targets)
LayerConfigurator(ApplicationContext context, params IEnumerable<Target> targets)
{
_context = context;
_targets = [.. targets];
Expand Down Expand Up @@ -66,9 +66,9 @@ public void Configure<TTarget1, TTarget2, TTarget3>(Action<TTarget1, TTarget2, T
configuration(ValueAs<TTarget1>(0), ValueAs<TTarget2>(1), ValueAs<TTarget3>(2));
}

bool Matches(params Type[] types)
bool Matches(params IList<Type> types)
{
if (_targets.Count != types.Length) { return false; }
if (_targets.Count != types.Count) { return false; }

for (var i = 0; i < _targets.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -244,10 +243,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"]));
Expand Down Expand Up @@ -278,19 +277,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 SwaggerSchemaHelper();
swaggerGenOptions.CustomSchemaIds(schemaHelper.GetSchemaId);

swaggerGenOptions.OrderActionsBy(apiDescription =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace Baked.Business.DomainAssemblies;

public class SwaggerSchemaHelper
{
readonly Dictionary<string, List<string>> _schemaNameRepetition = [];

public string GetSchemaId(Type modelType)
{
var id = DefaultSchemaIdSelector(modelType);

if (!_schemaNameRepetition.ContainsKey(id))
{
_schemaNameRepetition.Add(id, new List<string>());
}

var modelNameList = _schemaNameRepetition[id];
var fullName = modelType.FullName ?? string.Empty;
if (!string.IsNullOrEmpty(fullName) && !modelNameList.Contains(fullName))
{
modelNameList.Add(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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> codes) => descriptor.AddCodes(codes.ToArray());
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 IEnumerable<string> codes)
{
descriptor.Codes.AddRange(codes);

Expand All @@ -81,8 +80,7 @@ public static GeneratedAssemblyDescriptor AddCodes(this GeneratedAssemblyDescrip
public static GeneratedAssemblyDescriptor AddReferenceFrom<T>(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<Assembly> references) => descriptor.AddReferences(references.ToArray());
public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, params Assembly[] references)
public static GeneratedAssemblyDescriptor AddReferences(this GeneratedAssemblyDescriptor descriptor, params IEnumerable<Assembly> references)
{
descriptor.References.AddRange(references);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public abstract class CodeTemplateBase : ICodeTemplate
{
protected abstract IEnumerable<string> Render();

protected string Join(string separator, params string[] statements) =>
protected string Join(string separator, params IEnumerable<string> statements) =>
statements
.Where(s => !string.IsNullOrWhiteSpace(s))
.Join(separator ?? Environment.NewLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>() || propertyType.IsEnum)
Expand All @@ -31,7 +31,7 @@ public void Configure(LayerConfigurator configurator)
},
when: c =>
c.Type.Has<QueryAttribute>() &&
Regexes.StartsWithSingleBy().IsMatch(c.Method.Name)
Regexes.StartsWithSingleBy.IsMatch(c.Method.Name)
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static IClient<T> TheClient<T>(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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static DateTime ADateTime(this Stubber _,
) => new(year, month, day, hour, minute, second);

public static Dictionary<string, string> ADictionary(this Stubber giveMe) => giveMe.ADictionary<string, string>();
public static Dictionary<TKey, TValue> ADictionary<TKey, TValue>(this Stubber _, params (TKey, TValue)[] pairs)
public static Dictionary<TKey, TValue> ADictionary<TKey, TValue>(this Stubber _, params IEnumerable<(TKey, TValue)> pairs)
where TKey : notnull
=> pairs.ToDictionary(pair => pair.Item1, pair => pair.Item2);

Expand Down
4 changes: 2 additions & 2 deletions src/recipe/Baked.Recipe.Service.Application/Core/Regexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public static class AspNetCoreCorsExtensions
/// Returns 'AspNetCoreCors' feature with a single policy setup with given origins,
/// any header and any method
/// </note>
public static AspNetCoreCorsFeature AspNetCore(this CorsConfigurator configurator, params Setting<string>[] origins) =>
public static AspNetCoreCorsFeature AspNetCore(this CorsConfigurator configurator, params IEnumerable<Setting<string>> origins) =>
configurator.AspNetCore(
options => options
.AddPolicy("allow-origin", policy => policy
.WithOrigins(origins.Select(o => o.GetValue()).ToArray())
.WithOrigins([.. origins.Select(o => o.GetValue())])
.AllowAnyHeader()
.AllowAnyMethod()
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeModel> typeArguments) =>
TypeModelReference.IdOf(this, typeArguments);

public override bool Equals(object? obj) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading