diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs new file mode 100644 index 0000000000..911c6e746e --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.ApiVersioning; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc.Versioning +{ + public class HttpContextRequestedApiVersion : IRequestedApiVersion, ITransientDependency + { + public string Current => _httpContextAccessor.HttpContext?.GetRequestedApiVersion().ToString(); + + private readonly IHttpContextAccessor _httpContextAccessor; + + public HttpContextRequestedApiVersion(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/FixtureController.cs b/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/FixtureController.cs index 74d831e65e..7826bc5e7b 100644 --- a/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/FixtureController.cs +++ b/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/FixtureController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Volo.Abp.ApiVersioning; using Volo.Abp.Application.Services; using Volo.Abp.AspNetCore.Mvc; @@ -10,16 +11,23 @@ namespace Volo.Abp.Identity [Route("api/v{api-version:apiVersion}/identity/fixture")] public class FixtureController : AbpController, IRemoteService { + private readonly IRequestedApiVersion _requestedApiVersion; + + public FixtureController(IRequestedApiVersion requestedApiVersion) + { + _requestedApiVersion = requestedApiVersion; + } + [HttpGet, MapToApiVersion("2.0")] - public int Get() + public string Get() { - return 41; + return 41 + " - " + _requestedApiVersion.Current; } [HttpGet, MapToApiVersion("3.0")] - public int Get3() + public string Get3() { - return 42; + return 42 + " - " + _requestedApiVersion.Current; } [HttpPost] diff --git a/src/Volo.Abp/Volo/Abp/ApiVersioning/IRequestedApiVersion.cs b/src/Volo.Abp/Volo/Abp/ApiVersioning/IRequestedApiVersion.cs new file mode 100644 index 0000000000..3d8a31c694 --- /dev/null +++ b/src/Volo.Abp/Volo/Abp/ApiVersioning/IRequestedApiVersion.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.ApiVersioning +{ + public interface IRequestedApiVersion + { + string Current { get; } + } +}