Skip to content

Commit

Permalink
refactor(*): add support .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmet-cetinkaya committed Feb 2, 2024
1 parent 5059117 commit c3b9e3e
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 22 deletions.
11 changes: 6 additions & 5 deletions src/corePackages/Core.CodeGen/Code/CSharp/CSharpCodeInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static async Task AddCodeLinesAsPropertyAsync(string filePath, string[] c
{
string[] fileContent = await System.IO.File.ReadAllLinesAsync(filePath);
const string propertyStartRegex =
@"(public|protected|internal|protected internal|private protected|private)?\s*(?:const|static)?\s+(\w+(<.*>)?)\s+(\w+)\s*(?:\{.*\}|=.+;)";
@"(public|protected|internal|protected internal|private protected|private)?\s*(?:const|static|required)?\s+(\w+(<.*>)?)\s+(\w+)\s*(?:\{.*\}|=.+;)";

int indexToAdd = -1;
for (int i = 0; i < fileContent.Length; ++i)
Expand Down Expand Up @@ -256,16 +256,17 @@ public static async Task AddMethodToClass(string filePath, string className, str
classStartIndex = j;
break;
}
break;
}

int curlyBracketCountInMethod = 1;
int curlyBracketCountInClass = 1;
for (int i = classStartIndex + 1; i < fileContent.Count; ++i)
{
if (scopeBlockStartRegex.Match(input: fileContent[i]).Success)
++curlyBracketCountInMethod;
++curlyBracketCountInClass;
if (scopeBlockEndRegex.Match(input: fileContent[i]).Success)
--curlyBracketCountInMethod;
if (curlyBracketCountInMethod != 0)
--curlyBracketCountInClass;
if (curlyBracketCountInClass != 0)
continue;

classEndIndex = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ string projectPath
string fileContent = await System.IO.File.ReadAllTextAsync(filePath);
Regex propertyRegex =
new(
@"(public|protected|internal|protected internal|private protected|private)?\s+(?:const|static)?\s*((?:\w\.?)+\??)\s+(\w+)\s*\{.*\}"
@"(public|protected|internal|protected internal|private protected|private)?\s+(?:const|static|required)?\s*((?:\w\.?)+\??)\s+(\w+)\s*\{.*\}"
);
Regex builtInTypeRegex =
new(
Expand Down
14 changes: 14 additions & 0 deletions src/nArchGen/Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@
</ContentWithTargetPath>
</ItemGroup>

<ItemGroup>
<ContentWithTargetPath Remove="Templates\CRUD\Folders\Application\Services\PLURAL_ENTITY\ENTITYManager.cs.sbn" />
<ContentWithTargetPath Remove="Templates\CRUD\Folders\Application\Services\PLURAL_ENTITY\IENTITYService.cs.sbn" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\corePackages\Core.CodeGen\Core.CodeGen.csproj" />
<ProjectReference Include="..\..\corePackages\Core.CrossCuttingConcerns\Core.CrossCuttingConcerns.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Templates\CRUD\Folders\Application\Services\PLURAL_ENTITY\ENTITYManager.cs.sbn">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Templates\CRUD\Folders\Application\Services\PLURAL_ENTITY\IENTITYService.cs.sbn">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Create{{ entity.name | string.pascalcase }}Command : IRequest<Creat

public bool BypassCache { get; }
public string? CacheKey { get; }
public string CacheGroupKey => "Get{{ entity.name | string.pascalcase | string.plural }}";{{ end }}
public string[]? CacheGroupKey => ["Get{{ entity.name | string.pascalcase | string.plural }}"];{{ end }}

public class Create{{ entity.name | string.pascalcase }}CommandHandler : IRequestHandler<Create{{ entity.name | string.pascalcase }}Command, Created{{ entity.name | string.pascalcase }}Response>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Delete{{ entity.name | string.pascalcase }}Command : IRequest<Delet

public bool BypassCache { get; }
public string? CacheKey { get; }
public string CacheGroupKey => "Get{{ entity.name | string.pascalcase | string.plural }}";{{ end }}
public string[]? CacheGroupKey => ["Get{{ entity.name | string.pascalcase | string.plural }}"];{{ end }}

public class Delete{{ entity.name | string.pascalcase }}CommandHandler : IRequestHandler<Delete{{ entity.name | string.pascalcase }}Command, Deleted{{ entity.name | string.pascalcase }}Response>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Update{{ entity.name | string.pascalcase }}Command : IRequest<Updat

public bool BypassCache { get; }
public string? CacheKey { get; }
public string CacheGroupKey => "Get{{ entity.name | string.pascalcase | string.plural }}";{{ end }}
public string[]? CacheGroupKey => ["Get{{ entity.name | string.pascalcase | string.plural }}"];{{ end }}

public class Update{{ entity.name | string.pascalcase }}CommandHandler : IRequestHandler<Update{{ entity.name | string.pascalcase }}Command, Updated{{ entity.name | string.pascalcase }}Response>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class GetList{{ entity.name | string.pascalcase }}Query : IRequest<GetLis
public string[] Roles => new[] { Admin, Read };{{ end }}{{ if is_caching_used }}

public bool BypassCache { get; }
public string CacheKey => $"GetList{{ entity.name | string.pascalcase | string.plural }}({PageRequest.PageIndex},{PageRequest.PageSize})";
public string CacheGroupKey => "Get{{ entity.name | string.pascalcase | string.plural }}";
public string? CacheKey => $"GetList{{ entity.name | string.pascalcase | string.plural }}({PageRequest.PageIndex},{PageRequest.PageSize})";
public string? CacheGroupKey => "Get{{ entity.name | string.pascalcase | string.plural }}";
public TimeSpan? SlidingExpiration { get; }{{ end }}

public class GetList{{ entity.name | string.pascalcase }}QueryHandler : IRequestHandler<GetList{{ entity.name | string.pascalcase }}Query, GetListResponse<GetList{{ entity.name | string.pascalcase }}ListItemDto>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ using System.Linq.Expressions;

namespace Application.Services.{{ entity.name | string.pascalcase | string.plural }};

public class {{ entity.name | string.pascalcase | string.plural }}Manager : I{{ entity.name | string.pascalcase | string.plural }}Service
public class {{ entity.name | string.pascalcase }}Manager : I{{ entity.name | string.pascalcase }}Service
{
private readonly I{{ entity.name | string.camelcase | string.pascalcase }}Repository _{{ entity.name | string.camelcase }}Repository;
private readonly {{ entity.name | string.camelcase | string.pascalcase }}BusinessRules _{{ entity.name | string.camelcase }}BusinessRules;

public {{ entity.name | string.pascalcase | string.plural }}Manager(I{{ entity.name | string.camelcase | string.pascalcase }}Repository {{ entity.name | string.camelcase }}Repository, {{ entity.name | string.camelcase | string.pascalcase }}BusinessRules {{ entity.name | string.camelcase }}BusinessRules)
public {{ entity.name | string.pascalcase }}Manager(I{{ entity.name | string.camelcase | string.pascalcase }}Repository {{ entity.name | string.camelcase }}Repository, {{ entity.name | string.camelcase | string.pascalcase }}BusinessRules {{ entity.name | string.camelcase }}BusinessRules)
{
_{{ entity.name | string.camelcase }}Repository = {{ entity.name | string.camelcase }}Repository;
_{{ entity.name | string.camelcase }}BusinessRules = {{ entity.name | string.camelcase }}BusinessRules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using System.Linq.Expressions;

namespace Application.Services.{{ entity.name | string.pascalcase | string.plural }};

public interface I{{ entity.name | string.pascalcase | string.plural }}Service
public interface I{{ entity.name | string.pascalcase }}Service
{
Task<{{ entity.name | string.pascalcase }}?> GetAsync(
Expression<Func<{{ entity.name | string.pascalcase }}, bool>> predicate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
services.AddScoped<I{{ entity.name | string.pascalcase | string.plural }}Service, {{ entity.name | string.pascalcase | string.plural }}Manager>();
services.AddScoped<I{{ entity.name | string.pascalcase }}Service, {{ entity.name | string.pascalcase }}Manager>();
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{ if is_secured_operation_used }}using Application.Features.{{ feature_name | string.plural }}.Constants;
{{ if is_secured_operation_used }}using Application.Features.{{ feature_name }}.Constants;
{{ end }}using Application.Features.{{ feature_name }}.Rules;
using AutoMapper;{{ if is_secured_operation_used }}
using Core.Application.Pipelines.Authorization;{{ end }}{{ if is_caching_used }}
using Core.Application.Pipelines.Caching;{{ end }}{{ if is_logging_used }}
using Core.Application.Pipelines.Logging;{{ end }}{{ if is_transaction_used }}
using Core.Application.Pipelines.Transaction;{{ end }}
using MediatR;{{ if is_secured_operation_used }}
using static Application.Features.{{ feature_name | string.plural }}.Constants.{{ feature_name | string.plural }}OperationClaims;{{ end }}
using static Application.Features.{{ feature_name }}.Constants.{{ feature_name }}OperationClaims;{{ end }}

namespace Application.Features.{{ feature_name }}.Commands.{{ command_name | string.pascalcase }};

Expand All @@ -17,7 +17,7 @@ public class {{ command_name | string.pascalcase }}Command : IRequest<{{ command

public bool BypassCache { get; }
public string? CacheKey { get; }
public string CacheGroupKey => "Get{{ feature_name | string.pascalcase }}";{{ end }}
public string[]? CacheGroupKey => ["Get{{ feature_name | string.pascalcase }}"];{{ end }}

public class {{ command_name | string.pascalcase }}CommandHandler : IRequestHandler<{{ command_name | string.pascalcase }}Command, {{ command_name | string.pascalcase }}Response>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{ if is_secured_operation_used }}using Application.Features.{{ feature_name | string.plural }}.Constants;
{{ if is_secured_operation_used }}using Application.Features.{{ feature_name }}.Constants;
{{ end }}using Application.Features.{{ feature_name }}.Rules;
using AutoMapper;{{ if is_secured_operation_used }}
using Core.Application.Pipelines.Authorization;{{ end }}{{ if is_caching_used }}
using Core.Application.Pipelines.Caching;{{ end }}{{ if is_logging_used }}
using Core.Application.Pipelines.Logging;{{ end }}
using MediatR;{{ if is_secured_operation_used }}
using static Application.Features.{{ feature_name | string.plural }}.Constants.{{ feature_name | string.plural }}OperationClaims;{{ end }}
using static Application.Features.{{ feature_name }}.Constants.{{ feature_name }}OperationClaims;{{ end }}

namespace Application.Features.{{ feature_name }}.Queries.{{ query_name | string.pascalcase }};

Expand All @@ -15,8 +15,8 @@ public class {{ query_name | string.pascalcase }}Query : IRequest<{{ query_name
public string[] Roles => new[] { Admin, Read, {{ feature_name | string.pascalcase }}OperationClaims.{{ query_name }} };{{ end }}{{ if is_caching_used }}

public bool BypassCache { get; }
public string CacheKey => $"{{ query_name }}";
public string CacheGroupKey => "Get{{ feature_name | string.pascalcase }}";
public string? CacheKey => $"{{ query_name }}";
public string? CacheGroupKey => "Get{{ feature_name | string.pascalcase }}";
public TimeSpan? SlidingExpiration { get; }{{ end }}

public class {{ query_name | string.pascalcase }}QueryHandler : IRequestHandler<{{ query_name | string.pascalcase }}Query, {{ query_name | string.pascalcase }}Response>
Expand Down

0 comments on commit c3b9e3e

Please sign in to comment.