using Microsoft.Extensions.DependencyInjection; using SlnMesnac.Config; using SlnMesnac.Repository.service; using SlnMesnac.Repository.service.Impl; using SqlSugar; using System; using System.Collections.Generic; using System.Text; namespace SlnMesnac.Repository { public static class SqlsugarSetup { /// /// 注册SqlSugar /// /// public static void AddSqlSugarSetup(this IServiceCollection services) { services.AddSingleton(x => { var appConfig = x.GetService(); var connectConfigList = new List(); if (appConfig.sqlConfig != null) { foreach (var item in appConfig.sqlConfig) { var config = new ConnectionConfig() { ConfigId = item.configId, DbType = (DbType)item.dbType, ConnectionString = item.connStr, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, }; connectConfigList.Add(config); } } SqlSugarScope Db = new SqlSugarScope(connectConfigList, db => { db.Aop.OnLogExecuting = (sql, pars) => { }; }); return Db; }); } /// /// 注册Repository、Service服务 /// /// public static void AddServices(this IServiceCollection services) { //services.AddSingleton>(); services.AddSingleton(typeof(Repository<>)); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); } } }