Adding base controller
This commit is contained in:
23
MainProject/Controllers/BaseController.cs
Normal file
23
MainProject/Controllers/BaseController.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
22
MainProject/Controllers/VersionController.cs
Normal file
22
MainProject/Controllers/VersionController.cs
Normal file
@@ -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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,18 +89,14 @@ internal static class Program
|
|||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// REGISTER MIDDLEWARE HERE
|
// REGISTER MIDDLEWARE HERE
|
||||||
|
app.UseRouting();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
app.UseRouting();
|
app.MapControllers(); // This maps all controllers
|
||||||
|
|
||||||
app.MapControllerRoute(
|
|
||||||
name: "default",
|
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user