Skip to content

Commit

Permalink
Merge pull request #15 from sj-distributor/dotnet9
Browse files Browse the repository at this point in the history
Upgrade to dotnet9
  • Loading branch information
linwenda authored Dec 5, 2024
2 parents 6229030 + 589f13a commit acb2fd3
Show file tree
Hide file tree
Showing 92 changed files with 884 additions and 1,266 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![.NET](https://github.com/sj-distributor/Wax/actions/workflows/dotnet.yml/badge.svg)](https://github.com/sj-distributor/Wax/actions/workflows/dotnet.yml)
[![Nuget](https://img.shields.io/nuget/v/Wax.Template)](https://www.nuget.org/packages/Wax.Template)

WilTechs Architecture Solution Template for .NET 7
WilTechs Architecture Solution Template for .NET 9

## Getting Started

Expand Down
19 changes: 6 additions & 13 deletions Wax.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{75759C27-8B1
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{39D26C72-1BD3-4793-A455-F651830208E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wax.Messages", "src\Wax.Messages\Wax.Messages.csproj", "{E378200E-C104-4263-940C-24EAC2C5EF8B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wax.Api", "src\Wax.Api\Wax.Api.csproj", "{43B01DB0-00F2-48F3-962A-62236758544A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wax.UnitTests", "tests\Wax.UnitTests\Wax.UnitTests.csproj", "{AF0CBC87-76A5-4592-8673-7F4E2DA589F9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wax.IntegrationTests", "tests\Wax.IntegrationTests\Wax.IntegrationTests.csproj", "{1A1B03CC-0E42-46A0-9F7E-6DE18F05679B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wax.E2ETests", "tests\Wax.E2ETests\Wax.E2ETests.csproj", "{959A9B6E-2410-4F4A-A73C-1A69A41EE0A6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wax.Infrastructure", "src\Wax.Infrastructure\Wax.Infrastructure.csproj", "{7B557ED6-760C-4FF4-A720-E5D9D887F2C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -29,10 +27,6 @@ Global
{26DEE87D-1B2C-4788-B8DA-55F29896C03A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26DEE87D-1B2C-4788-B8DA-55F29896C03A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26DEE87D-1B2C-4788-B8DA-55F29896C03A}.Release|Any CPU.Build.0 = Release|Any CPU
{E378200E-C104-4263-940C-24EAC2C5EF8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E378200E-C104-4263-940C-24EAC2C5EF8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E378200E-C104-4263-940C-24EAC2C5EF8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E378200E-C104-4263-940C-24EAC2C5EF8B}.Release|Any CPU.Build.0 = Release|Any CPU
{43B01DB0-00F2-48F3-962A-62236758544A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43B01DB0-00F2-48F3-962A-62236758544A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43B01DB0-00F2-48F3-962A-62236758544A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -45,21 +39,20 @@ Global
{1A1B03CC-0E42-46A0-9F7E-6DE18F05679B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A1B03CC-0E42-46A0-9F7E-6DE18F05679B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A1B03CC-0E42-46A0-9F7E-6DE18F05679B}.Release|Any CPU.Build.0 = Release|Any CPU
{959A9B6E-2410-4F4A-A73C-1A69A41EE0A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{959A9B6E-2410-4F4A-A73C-1A69A41EE0A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{959A9B6E-2410-4F4A-A73C-1A69A41EE0A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{959A9B6E-2410-4F4A-A73C-1A69A41EE0A6}.Release|Any CPU.Build.0 = Release|Any CPU
{7B557ED6-760C-4FF4-A720-E5D9D887F2C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B557ED6-760C-4FF4-A720-E5D9D887F2C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B557ED6-760C-4FF4-A720-E5D9D887F2C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B557ED6-760C-4FF4-A720-E5D9D887F2C6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{26DEE87D-1B2C-4788-B8DA-55F29896C03A} = {75759C27-8B18-4FB5-97A8-570BBE311C6B}
{E378200E-C104-4263-940C-24EAC2C5EF8B} = {75759C27-8B18-4FB5-97A8-570BBE311C6B}
{43B01DB0-00F2-48F3-962A-62236758544A} = {75759C27-8B18-4FB5-97A8-570BBE311C6B}
{AF0CBC87-76A5-4592-8673-7F4E2DA589F9} = {39D26C72-1BD3-4793-A455-F651830208E7}
{1A1B03CC-0E42-46A0-9F7E-6DE18F05679B} = {39D26C72-1BD3-4793-A455-F651830208E7}
{959A9B6E-2410-4F4A-A73C-1A69A41EE0A6} = {39D26C72-1BD3-4793-A455-F651830208E7}
{7B557ED6-760C-4FF4-A720-E5D9D887F2C6} = {75759C27-8B18-4FB5-97A8-570BBE311C6B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {60CBA761-5D3C-4D33-B808-977512C7E6ED}
Expand Down
8 changes: 0 additions & 8 deletions src/Wax.Api/Authentication/CurrentUser.cs

This file was deleted.

33 changes: 17 additions & 16 deletions src/Wax.Api/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
using Mediator.Net;
using Microsoft.AspNetCore.Mvc;
using Wax.Messages.Commands.Customers;
using Wax.Messages.Dtos.Customers;
using Wax.Messages.Requests;
using Wax.Messages.Requests.Customers;

namespace Wax.Api.Controllers
{
[ApiController]
Expand All @@ -22,7 +15,8 @@ public CustomerController(IMediator mediator)
[ProducesResponseType(typeof(PaginatedResponse<CustomerShortInfo>), 200)]
public async Task<IActionResult> GetListAsync([FromQuery] GetCustomersRequest request)
{
var response = await _mediator.RequestAsync<GetCustomersRequest, PaginatedResponse<CustomerShortInfo>>(request);
var response =
await _mediator.RequestAsync<GetCustomersRequest, PaginatedResponse<CustomerShortInfo>>(request);

return Ok(response);
}
Expand All @@ -32,23 +26,30 @@ public async Task<IActionResult> GetListAsync([FromQuery] GetCustomersRequest re
public async Task<IActionResult> CreateAsync([FromBody] CreateCustomerCommand command)
{
var response = await _mediator.SendAsync<CreateCustomerCommand, CreateCustomerResponse>(command);
return Ok(response);
return CreatedAtAction("GetList", response);
}

[HttpPut]
[ProducesResponseType(200)]
public async Task<IActionResult> UpdateAsync([FromBody] UpdateCustomerCommand command)
[HttpPut("{customerId:guid}")]
[ProducesResponseType(204)]
public async Task<IActionResult> UpdateAsync(Guid customerId, [FromBody] UpdateCustomerModel model)
{
await _mediator.SendAsync(command);
return Ok();
await _mediator.SendAsync(new UpdateCustomerCommand
{
CustomerId = customerId,
Name = model.Name,
Contact = model.Contact,
Address = model.Address
});

return NoContent();
}

[HttpDelete]
[ProducesResponseType(200)]
[ProducesResponseType(204)]
public async Task<IActionResult> DeleteAsync([FromBody] DeleteCustomerCommand command)
{
await _mediator.SendAsync(command);
return Ok();
return NoContent();
}
}
}
101 changes: 0 additions & 101 deletions src/Wax.Api/Filters/GlobalExceptionFilter.cs

This file was deleted.

14 changes: 14 additions & 0 deletions src/Wax.Api/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Global using directives

global using Autofac;
global using Mediator.Net;
global using Microsoft.AspNetCore.Mvc;
global using Serilog;
global using Wax.Api.Extensions;
global using Wax.Api.Models;
global using Wax.Core;
global using Wax.Core.Commands.Customers;
global using Wax.Core.Requests;
global using Wax.Core.Requests.Customers;
global using Wax.Infrastructure;
global using ILogger = Serilog.ILogger;
8 changes: 8 additions & 0 deletions src/Wax.Api/Models/UpdateCustomerModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Wax.Api.Models;

public class UpdateCustomerModel
{
public string Name { get; set; }
public string Contact { get; set; }
public string Address { get; set; }
}
3 changes: 1 addition & 2 deletions src/Wax.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Autofac.Extensions.DependencyInjection;
using Serilog;

namespace Wax.Api;

Expand Down Expand Up @@ -47,7 +46,7 @@ private static IConfiguration GetConfiguration()
return builder.Build();
}

private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
private static ILogger CreateSerilogLogger(IConfiguration configuration)
{
var seqServerUrl = configuration["Serilog:Seq:ServerUrl"];
var seqApiKey = configuration["Serilog:Seq:ApiKey"];
Expand Down
24 changes: 6 additions & 18 deletions src/Wax.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using Autofac;
using Wax.Api.Authentication;
using Wax.Api.Extensions;
using Wax.Core.Services.Identity;
using Serilog;
using Wax.Api.Filters;
using Wax.Core;

namespace Wax.Api;
namespace Wax.Api;

public class Startup
{
Expand All @@ -23,10 +15,10 @@ public Startup(IConfiguration configuration)
// called by the runtime before the ConfigureContainer method, below.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(options => { options.Filters.Add<GlobalExceptionFilter>(); });
services.AddControllers();
services.AddOptions();
services.AddCustomSwagger();
services.AddScoped<ICurrentUser, CurrentUser>();
services.AddScoped<IUserContext, UserContext>();
services.AddLogging();
services.AddHttpContextAccessor();

Expand All @@ -41,13 +33,9 @@ public void ConfigureContainer(ContainerBuilder builder)
{
var serviceProvider = _serviceCollection.BuildServiceProvider();

var currentUser = serviceProvider.GetRequiredService<ICurrentUser>();
var userContext = serviceProvider.GetRequiredService<IUserContext>();

// Register your own things directly with Autofac here. Don't
// call builder.Populate(), that happens in AutofacServiceProviderFactory
// for you.
builder.RegisterModule(new ApplicationModule(Log.Logger, currentUser, Configuration,
typeof(Startup).Assembly));
ApplicationStartup.Initialize(builder, "", Log.Logger, userContext, Configuration);
}

// Configure is where you add middleware. This is called after
Expand All @@ -58,7 +46,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Barcode.Api.xml"); });
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Wax.Api.xml"); });
}

app.UseRouting();
Expand Down
51 changes: 51 additions & 0 deletions src/Wax.Api/UserContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Security.Claims;

namespace Wax.Api;

public class UserContext : IUserContext
{
private readonly IHttpContextAccessor _httpContextAccessor;

private string _cachedUserId;

public UserContext(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}

public string GetCurrentUserId()
{
if (!string.IsNullOrEmpty(_cachedUserId))
{
return _cachedUserId;
}

SetCurrentUserId();

return _cachedUserId;
}

public void SetCurrentUserId(string userId = null)
{
if (userId == null)
{
var user = _httpContextAccessor.HttpContext?.User;
if (user is null)
{
throw new InvalidOperationException("HttpContext must be present to inspect auth info.");
}

var userIdClaim = user.FindFirst("sub") ?? user.FindFirst(ClaimTypes.NameIdentifier);
if (userIdClaim is null)
{
throw new InvalidOperationException("User Id was not present in the request token.");
}

_cachedUserId = userIdClaim.Value;
}
else
{
_cachedUserId = userId;
}
}
}
Loading

0 comments on commit acb2fd3

Please sign in to comment.