Skip to content

Commit 4817bad

Browse files
committed
Merge branch 'develop' of https://github.com/Amitpnk/Onion-architecture-ASP.NET-Core into develop
2 parents d301a04 + 30b8109 commit 4817bad

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

OnionArchitecture/OA.Infrastructure/Extension/ConfigureServiceContainer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AutoMapper;
2+
using Microsoft.AspNetCore.Mvc;
23
using Microsoft.EntityFrameworkCore;
34
using Microsoft.Extensions.Configuration;
45
using Microsoft.Extensions.DependencyInjection;
@@ -90,6 +91,16 @@ public static void AddController(this IServiceCollection serviceCollection)
9091
// //var assembly = AppDomain.CurrentDomain.Load("OA.Service");
9192
// services.AddMediatR(Assembly.GetExecutingAssembly());
9293
//}
94+
public static void AddVersion(this IServiceCollection serviceCollection)
95+
{
96+
serviceCollection.AddApiVersioning(config =>
97+
{
98+
config.DefaultApiVersion = new ApiVersion(1, 0);
99+
config.AssumeDefaultVersionWhenUnspecified = true;
100+
config.ReportApiVersions = true;
101+
});
102+
}
103+
93104

94105
}
95106
}

OnionArchitecture/OA.Infrastructure/OA.Infrastructure.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.5" />
15+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
1516
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
1617
<PrivateAssets>all</PrivateAssets>
1718
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

OnionArchitecture/OA.Service/Features/CustomerFeatures/Commands/UpdateCustomerCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public async Task<int> Handle(UpdateCustomerCommand request, CancellationToken c
3737
}
3838
else
3939
{
40-
var customer = new Customer();
41-
customer.CustomerName = request.CustomerName;
42-
customer.ContactName = request.ContactName;
40+
cust.CustomerName = request.CustomerName;
41+
cust.ContactName = request.ContactName;
42+
_context.Customers.Update(cust);
4343
await _context.SaveChangesAsync();
4444
return cust.Id;
4545
}

OnionArchitecture/OA/Controllers/CustomerController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace OA.Controllers
99
{
10-
[Route("api/Customer")]
1110
[ApiController]
11+
[Route("api/v{version:apiVersion}/Customer")]
12+
[ApiVersion("1.0")]
1213
public class CustomerController : ControllerBase
1314
{
1415
private IMediator _mediator;
@@ -40,7 +41,7 @@ public async Task<IActionResult> Delete(int id)
4041
}
4142

4243

43-
[HttpPut("[action]")]
44+
[HttpPut("{id}")]
4445
public async Task<IActionResult> Update(int id, UpdateCustomerCommand command)
4546
{
4647
if (id != command.Id)

OnionArchitecture/OA/Controllers/MailController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
namespace OA.Controllers
77
{
8-
[Route("api/Mail")]
98
[ApiController]
9+
[Route("api/v{version:apiVersion}/Mail")]
10+
[ApiVersion("1.0")]
1011
public class MailController : ControllerBase
1112
{
1213
private readonly IMailService mailService;

OnionArchitecture/OA/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void ConfigureServices(IServiceCollection services)
4343

4444
services.AddMediatorCQRS();
4545

46+
services.AddVersion();
4647

4748
}
4849

0 commit comments

Comments
 (0)