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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user