using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace StaffManagement.Database
{
    static public class DbInit
    {
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder SMDbInit(this IApplicationBuilder app) {
            app.ApplicationServices.GetService<SMDbContext>().Init();
            return app;
        }
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <param name="db">数据库上下文</param>
        /// <returns></returns>
        public static SMDbContext Init(this SMDbContext db) {
            db.Database.EnsureCreated();
            return db;
        }
    }
}
