using System;
using Falcon.Extend;
using FAuth.DataBase;
using FAuth.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace FAuth.Controllers
{
    /// <summary>
    /// 控制器类基类
    /// </summary>
    //[Route("[Controller]/[Action]")]
    public abstract class ControllerBase<LoggerType>:Controller
    {
        /// <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; }

        /// <summary>
        /// 通过日志组件和服务集合生成控制器
        /// </summary>
        /// <param name="logger">控制器日志组件</param>
        /// <param name="service">服务集合</param>
        public ControllerBase(ILogger<LoggerType> logger,IServiceProvider service) {
            this.Logger = logger;
            this.Services = service;
            this.Db = service.GetService<FAuthDb>();
            this.Cache = service.GetService<ICacheProvider>();
        }

    }
}
