Skip to content

Commit

Permalink
Merge pull request #12 from meysamhadeli/feature/update-to-dotnet-8
Browse files Browse the repository at this point in the history
feat: update to .Net 8.
  • Loading branch information
meysamhadeli authored Jul 24, 2024
2 parents 2a7334e + bfaed42 commit ada52da
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 285 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.303",
"rollForward": "latestFeature"
}
}
2 changes: 1 addition & 1 deletion src/Api/src/Api.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Api</RootNamespace>
</PropertyGroup>
Expand Down
185 changes: 92 additions & 93 deletions src/BuildingBlocks/BuildingBlocks.csproj

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions src/BuildingBlocks/CAP/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IServiceCollection AddCustomCap(this IServiceCollection services)
{
x.UseInMemoryStorage();
x.UseInMemoryMessageQueue();

x.UseDashboard();
x.FailedRetryCount = 5;
x.FailedThresholdCallback = failed =>
Expand All @@ -40,11 +40,13 @@ public static IServiceCollection AddCustomCap(this IServiceCollection services)
.AsImplementedInterfaces()
.WithScopedLifetime());

services.AddOpenTelemetryTracing(builder => builder
.AddAspNetCoreInstrumentation()
.AddCapInstrumentation()
.AddJaegerExporter()
);
services.AddOpenTelemetry()
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation()
.AddCapInstrumentation()
.AddJaegerExporter();
});

return services;
}
Expand Down
20 changes: 8 additions & 12 deletions src/BuildingBlocks/Caching/CachingBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EasyCaching.Core;
using EasyCaching.Core;
using MediatR;
using Microsoft.Extensions.Logging;

Expand All @@ -8,29 +8,25 @@ public class CachingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest,
where TRequest : notnull, IRequest<TResponse>
where TResponse : notnull
{
private readonly ICacheRequest _cacheRequest;
private readonly IEasyCachingProvider _cachingProvider;
private readonly ILogger<CachingBehavior<TRequest, TResponse>> _logger;
private readonly int defaultCacheExpirationInHours = 1;

public CachingBehavior(IEasyCachingProviderFactory cachingFactory,
ILogger<CachingBehavior<TRequest, TResponse>> logger,
ICacheRequest cacheRequest)
ILogger<CachingBehavior<TRequest, TResponse>> logger)
{
_logger = logger;
_cachingProvider = cachingFactory.GetCachingProvider("mem");
_cacheRequest = cacheRequest;
}


public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next,
CancellationToken cancellationToken)
{
if (request is not ICacheRequest || _cacheRequest == null)
if (request is not ICacheRequest cacheRequest)
// No cache request found, so just continue through the pipeline
return await next();

var cacheKey = _cacheRequest.CacheKey;
var cacheKey = cacheRequest.CacheKey;
var cachedResponse = await _cachingProvider.GetAsync<TResponse>(cacheKey);
if (cachedResponse.Value != null)
{
Expand All @@ -41,7 +37,7 @@ public async Task<TResponse> Handle(TRequest request, CancellationToken cancella

var response = await next();

var expirationTime = _cacheRequest.AbsoluteExpirationRelativeToNow ??
var expirationTime = cacheRequest.AbsoluteExpirationRelativeToNow ??
DateTime.Now.AddHours(defaultCacheExpirationInHours);

await _cachingProvider.SetAsync(cacheKey, response, expirationTime.TimeOfDay);
Expand All @@ -51,4 +47,4 @@ public async Task<TResponse> Handle(TRequest request, CancellationToken cancella

return response;
}
}
}
19 changes: 5 additions & 14 deletions src/BuildingBlocks/Caching/InvalidateCachingBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EasyCaching.Core;
using MediatR;
using Microsoft.Extensions.Logging;
Expand All @@ -14,28 +10,23 @@ public class InvalidateCachingBehavior<TRequest, TResponse> : IPipelineBehavior<
{
private readonly ILogger<InvalidateCachingBehavior<TRequest, TResponse>> _logger;
private readonly IEasyCachingProvider _cachingProvider;
private readonly IInvalidateCacheRequest _invalidateCacheRequest;


public InvalidateCachingBehavior(IEasyCachingProviderFactory cachingFactory,
ILogger<InvalidateCachingBehavior<TRequest, TResponse>> logger,
IInvalidateCacheRequest invalidateCacheRequest)
ILogger<InvalidateCachingBehavior<TRequest, TResponse>> logger)
{
_logger = logger;
_cachingProvider = cachingFactory.GetCachingProvider("mem");
_invalidateCacheRequest = invalidateCacheRequest;
}

public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
if (request is not IInvalidateCacheRequest || _invalidateCacheRequest == null)
if (request is not IInvalidateCacheRequest invalidateCacheRequest)
{
// No cache request found, so just continue through the pipeline
return await next();
}

var cacheKey = _invalidateCacheRequest.CacheKey;
var cacheKey = invalidateCacheRequest.CacheKey;
var response = await next();

await _cachingProvider.RemoveAsync(cacheKey);
Expand All @@ -45,4 +36,4 @@ public async Task<TResponse> Handle(TRequest request, CancellationToken cancella
return response;
}
}
}
}
5 changes: 2 additions & 3 deletions src/BuildingBlocks/Logging/LoggingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger)
_logger = logger;
}


public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next,
CancellationToken cancellationToken)
{
const string prefix = nameof(LoggingBehavior<TRequest, TResponse>);

Expand Down
3 changes: 2 additions & 1 deletion src/BuildingBlocks/MediatR/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public static class Extensions
{
public static IServiceCollection AddCustomMediatR(this IServiceCollection services, params Assembly [] assemblies)
{
services.AddMediatR(assemblies);
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(assemblies));

services.AddScoped(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>));
Expand Down
6 changes: 4 additions & 2 deletions src/BuildingBlocks/Validation/ValidationBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public ValidationBehavior(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)

public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next,
CancellationToken cancellationToken)
{
_validator = _serviceProvider.GetService<IValidator<TRequest>>();
if (_validator is null)
return await next();

await _validator.HandleValidationAsync(request);

return await next();
Expand Down
5 changes: 3 additions & 2 deletions src/BuildingBlocks/Web/BaseController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AutoMapper;
using MediatR;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Mapster;
using MapsterMapper;

namespace BuildingBlocks.Web;

Expand Down
25 changes: 0 additions & 25 deletions src/Modules/Booking/.dockerignore

This file was deleted.

4 changes: 2 additions & 2 deletions src/Modules/Booking/src/Booking/Booking.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
16 changes: 5 additions & 11 deletions src/Modules/Booking/src/Booking/Data/EfTxBookingBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Text.Json;
using BuildingBlocks.Domain;
using BuildingBlocks.EFCore;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Booking.Data;

Expand All @@ -22,16 +20,12 @@ public EfTxBookingBehavior(
_busPublisher = busPublisher;
_dbContext = dbContext;
}

public async Task<TResponse> Handle(
TRequest request,
CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
_logger.LogInformation(
"{Prefix} Handled command {MediatrRequest}",
nameof(EfTxBookingBehavior<TRequest, TResponse>),
typeof(TRequest).FullName);
"{Prefix} Handled command {MediatrRequest}",
nameof(EfTxBookingBehavior<TRequest, TResponse>),
typeof(TRequest).FullName);

_logger.LogDebug(
"{Prefix} Handled command {MediatrRequest} with content {RequestContent}",
Expand Down Expand Up @@ -60,7 +54,7 @@ public async Task<TResponse> Handle(

// ref: https://learn.microsoft.com/en-us/ef/ef6/fundamentals/connection-resiliency/retry-logic?redirectedfrom=MSDN#solution-manually-call-execution-strategy
await _dbContext.ExecuteTransactionalAsync(cancellationToken);

return response;
}
}
Expand Down
25 changes: 0 additions & 25 deletions src/Modules/Flight/.dockerignore

This file was deleted.

14 changes: 5 additions & 9 deletions src/Modules/Flight/src/Flight/Data/EfTxFlightBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading;
using System.Threading.Tasks;
using BuildingBlocks.Domain;
using BuildingBlocks.EFCore;
using MediatR;
using Microsoft.Extensions.Logging;

Expand All @@ -26,15 +25,12 @@ public EfTxFlightBehavior(
_dbContext = dbContext;
}

public async Task<TResponse> Handle(
TRequest request,
CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
_logger.LogInformation(
"{Prefix} Handled command {MediatrRequest}",
nameof(EfTxFlightBehavior<TRequest, TResponse>),
typeof(TRequest).FullName);
"{Prefix} Handled command {MediatrRequest}",
nameof(EfTxFlightBehavior<TRequest, TResponse>),
typeof(TRequest).FullName);

_logger.LogDebug(
"{Prefix} Handled command {MediatrRequest} with content {RequestContent}",
Expand Down Expand Up @@ -63,7 +59,7 @@ public async Task<TResponse> Handle(

// ref: https://learn.microsoft.com/en-us/ef/ef6/fundamentals/connection-resiliency/retry-logic?redirectedfrom=MSDN#solution-manually-call-execution-strategy
await _dbContext.ExecuteTransactionalAsync(cancellationToken);

return response;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Modules/Flight/src/Flight/Flight.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
25 changes: 0 additions & 25 deletions src/Modules/Identity/.dockerignore

This file was deleted.

Loading

0 comments on commit ada52da

Please sign in to comment.