FalconSSO/FAuth/Controllers/ControllerBase.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2020-03-30 10:12:52 +08:00
using System;
using Falcon.Extend;
using FAuth.DataBase;
2020-03-30 10:12:52 +08:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
2020-03-30 10:12:52 +08:00
using Microsoft.Extensions.Logging;
namespace FAuth.Controllers
{
/// <summary>
/// 控制器类基类
/// </summary>
2020-03-30 16:10:51 +08:00
public abstract class ControllerBase<LoggerType>:Controller
2020-03-30 10:12:52 +08:00
{
/// <summary>
/// 日志记录服务
/// </summary>
public ILogger Logger { get; set; }
/// <summary>
/// 服务集合
/// </summary>
public IServiceProvider Services { get; set; }
/// <summary>
/// 数据库
/// </summary>
public FAuthDb Db { get; set; }
/// <summary>
/// 数据缓冲
/// </summary>
public ICacheProvider Cache { get; set; }
2020-03-30 10:12:52 +08:00
/// <summary>
/// 通过日志组件和服务集合生成控制器
/// </summary>
/// <param name="logger">控制器日志组件</param>
/// <param name="service">服务集合</param>
2020-03-30 16:10:51 +08:00
public ControllerBase(ILogger<LoggerType> logger,IServiceProvider service) {
2020-03-30 10:12:52 +08:00
this.Logger = logger;
this.Services = service;
this.Db = service.GetService<FAuthDb>();
this.Cache = service.GetService<ICacheProvider>();
2020-03-30 10:12:52 +08:00
}
}
}