using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Seyounth.Hyosung.Data.Entities; using Seyounth.Hyosung.Data.Repositories; using Seyounth.Hyosung.Data.Services; using Seyounth.Hyosung.Data.Services.Hyosung; using SqlSugar; namespace Seyounth.Hyosung.Data; public static class ServiceExtensions { public static IServiceCollection AddHyosungData(this IServiceCollection services, ConfigurationManager configuration) { var connectionString = configuration.GetConnectionString("DefaultConnection"); services.AddSingleton(s => { //#if RELEASE // SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() // { // DbType = DbType.SqlServer, // ConnectionString = connectionString, // IsAutoCloseConnection = true, // } // ); //#elif DEBUG SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() { DbType = DbType.Sqlite, ConnectionString = "Data Source=hyosung.db", IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute } ); //#endif return sqlSugar; }); services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); return services; } public static void UseHyosungData(this IServiceProvider provider) { var db = provider.GetRequiredService(); db.DbMaintenance.CreateDatabase(); db.CodeFirst.InitTables(typeof(VarietyEntity), typeof(PalletEntity), typeof(ScannedYarnEntity), typeof(TrayEntity), typeof(AgvBinEntity), typeof(DictEntity)); } }