使用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(); var services = new ServiceCollection();
//services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); //services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
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<IAlarmDataService, AlarmDataService>();
services.AddScoped<IBlankingDataService, BlankingDataService>(); services.AddScoped<IBlankingDataService, BlankingDataService>();
+4 -9
View File
@@ -470,8 +470,6 @@ namespace JY.Inspection
_speech.SelectVoice(neededVoice.VoiceInfo.Name); _speech.SelectVoice(neededVoice.VoiceInfo.Name);
} }
IocConfig.Initialize();
LogManagerControl.AddLog("程序已启动", LogAddtype.local); LogManagerControl.AddLog("程序已启动", LogAddtype.local);
} }
@@ -1999,8 +1997,7 @@ namespace JY.Inspection
{ {
try try
{ {
Repository<FeedingData> repository = new Repository<FeedingData>(); FeedingDataService feedingService = IocConfig.Provider.GetService<FeedingDataService>();
var feedingService = new FeedingDataService(repository);
List<FeedingData> list = (List<FeedingData>)obj; List<FeedingData> list = (List<FeedingData>)obj;
if (list != null) if (list != null)
@@ -2092,8 +2089,7 @@ namespace JY.Inspection
///1# 进站条码 ///1# 进站条码
} }
Repository<FeedingData> repository = new Repository<FeedingData>(); FeedingDataService service = (FeedingDataService)IocConfig.Provider.GetService<IFeedingDataService>();
FeedingDataService service = new FeedingDataService(repository);
for (int i = 0; i < listBarOut.Count; i++) for (int i = 0; i < listBarOut.Count; i++)
{ {
@@ -2508,9 +2504,8 @@ namespace JY.Inspection
{ {
try try
{ {
//BlankingDataService service = IocConfig.Provider.GetService<BlankingDataService>(); BlankingDataService service =
Repository<BlankingData> repository = new Repository<BlankingData>(); (BlankingDataService)IocConfig.Provider.GetService<IBlankingDataService>();
var service = new BlankingDataService(repository);
List<BlankingData> list = (List<BlankingData>)obj; List<BlankingData> list = (List<BlankingData>)obj;
if (list != null) if (list != null)
+4
View File
@@ -1,4 +1,5 @@
using HslCommunication; using HslCommunication;
using JY.DAL;
using JY.Utility; using JY.Utility;
using System; using System;
using System.Reflection; using System.Reflection;
@@ -33,6 +34,9 @@ namespace JY.Inspection
IniFileHelper.CreateIniFile(Application.StartupPath + "\\Config\\", "Configure.ini"); IniFileHelper.CreateIniFile(Application.StartupPath + "\\Config\\", "Configure.ini");
string mutexName = Assembly.GetEntryAssembly().FullName; string mutexName = Assembly.GetEntryAssembly().FullName;
string title = IniFileHelper.ReadIniData("SYSTEM_CONFIGURE", "Project_Name"); string title = IniFileHelper.ReadIniData("SYSTEM_CONFIGURE", "Project_Name");
IocConfig.Initialize();
mFrmMain = new HomeForm(); mFrmMain = new HomeForm();
bool isFirst; bool isFirst;
using (new Mutex(false, mutexName, out isFirst)) using (new Mutex(false, mutexName, out isFirst))