File tree Expand file tree Collapse file tree 5 files changed +17
-2
lines changed Expand file tree Collapse file tree 5 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 11using AutoMapper ;
2+ using Microsoft . AspNetCore . Mvc ;
23using Microsoft . EntityFrameworkCore ;
34using Microsoft . Extensions . Configuration ;
45using 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}
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 77
88namespace 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 ;
Original file line number Diff line number Diff line change 55
66namespace 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 ;
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ public void ConfigureServices(IServiceCollection services)
4343
4444 services . AddMediatorCQRS ( ) ;
4545
46+ services . AddVersion ( ) ;
4647
4748 }
4849
You can’t perform that action at this time.
0 commit comments