Skip to content

Commit 847345f

Browse files
committed
verssioning
1 parent ee7530e commit 847345f

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
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/Controllers/CustomerController.cs

Lines changed: 2 additions & 1 deletion
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;

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)