使用IOC获取定义的数据服务

This commit is contained in:
liming 蔡
2026-07-14 19:24:01 +08:00
parent 8c6c9a5dc1
commit 4e6992b78c
3 changed files with 9 additions and 10 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ namespace JY.DAL
var services = new ServiceCollection();
//services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.AddScoped<IRepository<BlankingData>, Repository<BlankingData>>();
//services.AddScoped<IRepository<BlankingData>, Repository<BlankingData>>();
services.AddScoped<IAlarmDataService, AlarmDataService>();
services.AddScoped<IBlankingDataService, BlankingDataService>();
+4 -9
View File
@@ -470,8 +470,6 @@ namespace JY.Inspection
_speech.SelectVoice(neededVoice.VoiceInfo.Name);
}
IocConfig.Initialize();
LogManagerControl.AddLog("程序已启动", LogAddtype.local);
}
@@ -1999,8 +1997,7 @@ namespace JY.Inspection
{
try
{
Repository<FeedingData> repository = new Repository<FeedingData>();
var feedingService = new FeedingDataService(repository);
FeedingDataService feedingService = IocConfig.Provider.GetService<FeedingDataService>();
List<FeedingData> list = (List<FeedingData>)obj;
if (list != null)
@@ -2092,8 +2089,7 @@ namespace JY.Inspection
///1# 进站条码
}
Repository<FeedingData> repository = new Repository<FeedingData>();
FeedingDataService service = new FeedingDataService(repository);
FeedingDataService service = (FeedingDataService)IocConfig.Provider.GetService<IFeedingDataService>();
for (int i = 0; i < listBarOut.Count; i++)
{
@@ -2508,9 +2504,8 @@ namespace JY.Inspection
{
try
{
//BlankingDataService service = IocConfig.Provider.GetService<BlankingDataService>();
Repository<BlankingData> repository = new Repository<BlankingData>();
var service = new BlankingDataService(repository);
BlankingDataService service =
(BlankingDataService)IocConfig.Provider.GetService<IBlankingDataService>();
List<BlankingData> list = (List<BlankingData>)obj;
if (list != null)
+4
View File
@@ -1,4 +1,5 @@
using HslCommunication;
using JY.DAL;
using JY.Utility;
using System;
using System.Reflection;
@@ -33,6 +34,9 @@ namespace JY.Inspection
IniFileHelper.CreateIniFile(Application.StartupPath + "\\Config\\", "Configure.ini");
string mutexName = Assembly.GetEntryAssembly().FullName;
string title = IniFileHelper.ReadIniData("SYSTEM_CONFIGURE", "Project_Name");
IocConfig.Initialize();
mFrmMain = new HomeForm();
bool isFirst;
using (new Mutex(false, mutexName, out isFirst))