2025-03-16 03:17:36 +08:00
|
|
|
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<ISqlSugarClient>(s =>
|
|
|
|
{
|
2025-03-18 05:24:15 +08:00
|
|
|
//#if RELEASE
|
2025-03-16 03:17:36 +08:00
|
|
|
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
|
2025-03-18 05:24:15 +08:00
|
|
|
{
|
|
|
|
DbType = DbType.SqlServer,
|
|
|
|
ConnectionString = connectionString,
|
|
|
|
IsAutoCloseConnection = true,
|
|
|
|
}
|
2025-03-16 03:17:36 +08:00
|
|
|
);
|
2025-03-18 05:24:15 +08:00
|
|
|
//#elif DEBUG
|
|
|
|
//SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
|
|
|
|
// {
|
|
|
|
// DbType = DbType.Sqlite,
|
|
|
|
// ConnectionString = "Data Source=hyosung.db",
|
|
|
|
// IsAutoCloseConnection = true,
|
|
|
|
// InitKeyType = InitKeyType.Attribute
|
|
|
|
// }
|
|
|
|
//);
|
|
|
|
//#endif
|
2025-03-16 03:17:36 +08:00
|
|
|
return sqlSugar;
|
|
|
|
});
|
2025-03-21 10:19:10 +08:00
|
|
|
services.AddSingleton(typeof(IRepository<>), typeof(Repository<>));
|
2025-03-16 03:17:36 +08:00
|
|
|
services.AddSingleton<IVarietyService, VarietyService>();
|
|
|
|
services.AddSingleton<IYarnService, YarnService>();
|
|
|
|
services.AddSingleton<ITrayService, TrayService>();
|
|
|
|
services.AddSingleton<IAgvBinService, AgvBinService>();
|
|
|
|
services.AddSingleton<IDictService, DictService>();
|
|
|
|
services.AddSingleton<IHyosungWmsService, HyosungWmsService>();
|
2025-03-17 22:17:28 +08:00
|
|
|
services.AddSingleton<IPalletService, PalletService>();
|
2025-03-16 03:17:36 +08:00
|
|
|
return services;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void UseHyosungData(this IServiceProvider provider)
|
|
|
|
{
|
2025-03-18 05:24:15 +08:00
|
|
|
//var db = provider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
//db.DbMaintenance.CreateDatabase();
|
|
|
|
//db.CodeFirst.InitTables(typeof(VarietyEntity),
|
|
|
|
// typeof(PalletEntity),
|
|
|
|
// typeof(ScannedYarnEntity),
|
|
|
|
// typeof(TrayEntity),
|
|
|
|
// typeof(AgvBinEntity),
|
|
|
|
// typeof(DictEntity));
|
2025-03-16 03:17:36 +08:00
|
|
|
}
|
|
|
|
}
|