diff --git a/MainProject/Controllers/BaseController.cs b/MainProject/Controllers/BaseController.cs new file mode 100644 index 0000000..2127fd3 --- /dev/null +++ b/MainProject/Controllers/BaseController.cs @@ -0,0 +1,23 @@ +using System.Net; +using Microsoft.AspNetCore.Mvc; +using BasicDotnetTemplate.MainProject.Models.Settings; + +[Controller] +public abstract class BaseController : ControllerBase +{ + protected readonly IConfiguration _configuration; + protected readonly AppSettings _appSettings; + + public BaseController( + IConfiguration configuration + ) + { + _configuration = configuration; + _appSettings = new AppSettings(); + _configuration.GetSection("AppSettings").Bind(_appSettings); + } + + + + +} \ No newline at end of file diff --git a/MainProject/Controllers/VersionController.cs b/MainProject/Controllers/VersionController.cs new file mode 100644 index 0000000..6866cf0 --- /dev/null +++ b/MainProject/Controllers/VersionController.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Mvc; +using BasicDotnetTemplate.MainProject.Models.Settings; + +namespace BasicDotnetTemplate.MainProject.Controllers +{ + public class VersionController : BaseController + { + public VersionController( + IConfiguration configuration + ) : base(configuration) + { + + } + + [HttpGet] + [Route("version")] + public IActionResult GetVersion() + { + return Ok(new { version = _appSettings.Settings.Version }); + } + } +} \ No newline at end of file diff --git a/MainProject/Program.cs b/MainProject/Program.cs index 5016994..7c738e8 100644 --- a/MainProject/Program.cs +++ b/MainProject/Program.cs @@ -89,18 +89,14 @@ internal static class Program var app = builder.Build(); // REGISTER MIDDLEWARE HERE + app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseRouting(); - - app.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}" - ); + app.MapControllers(); // This maps all controllers if (app.Environment.IsDevelopment()) {