Last active
May 24, 2019 12:40
-
-
Save dylanberry/1984e587ea553c6fe7e11d39c2d8b12e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Mvc.Filters; | |
namespace VersionCheck.API.VersionCheck | |
{ | |
public class MinimumClientVersionFilter : IActionFilter | |
{ | |
private readonly IVersionCheckService _versionCheckHelper; | |
public MinimumClientVersionFilter(IVersionCheckService versionCheckHelper) | |
{ | |
_versionCheckHelper = versionCheckHelper; | |
} | |
public void OnActionExecuting(ActionExecutingContext context) | |
{ | |
_versionCheckHelper.PerformVersionCheck(context.HttpContext.Request); | |
} | |
public void OnActionExecuted(ActionExecutedContext context) | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Microsoft.AspNetCore.Mvc; | |
using VersionCheck.API.VersionCheck; | |
namespace VersionCheck.API.Controllers | |
{ | |
[ServiceFilter(typeof(MinimumClientVersionFilter))] | |
[Route("api/[controller]")] | |
[ApiController] | |
public class ValuesController : ControllerBase | |
{ | |
// GET api/values | |
[HttpGet] | |
public ActionResult<IEnumerable<string>> Get() | |
{ | |
return new string[] { "value1", "value2" }; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment