From 0093c48cb1829abbeb8736f742446919ecd4e281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Tue, 29 Oct 2024 15:32:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=91=E8=B0=83=E5=BA=A6=E5=99=A8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=84=E7=90=86=E5=99=A8=E6=97=B6=EF=BC=8C=E5=8D=B3?= =?UTF-8?q?=E6=97=B6=E4=BB=8Eioc=E8=A7=A3=E6=9E=90=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E5=A4=84=E7=90=86=E5=99=A8=E7=9A=84?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E6=B3=A8=E5=85=A5=E3=80=82?= =?UTF-8?q?https://github.com/NewLifeX/AntJob/issues/15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AntJob.Agent/AntJob.Agent.csproj | 2 +- AntJob.Data/AntJob.Data.csproj | 2 +- AntJob.Extensions/AntJob.Extensions.csproj | 2 +- AntJob.Server/AntJob.Server.csproj | 2 +- AntJob.Web/AntJob.Web.csproj | 6 +++--- AntJob/AntJob.csproj | 6 +++--- AntJob/Scheduler.cs | 15 +++++++++++---- Samples/HisData/HisData.csproj | 2 +- Samples/HisWeb/HisWeb.csproj | 2 +- 9 files changed, 23 insertions(+), 16 deletions(-) diff --git a/AntJob.Agent/AntJob.Agent.csproj b/AntJob.Agent/AntJob.Agent.csproj index 347bbb9..2dab09c 100644 --- a/AntJob.Agent/AntJob.Agent.csproj +++ b/AntJob.Agent/AntJob.Agent.csproj @@ -32,7 +32,7 @@ - + diff --git a/AntJob.Data/AntJob.Data.csproj b/AntJob.Data/AntJob.Data.csproj index 03b2194..e59dbc6 100644 --- a/AntJob.Data/AntJob.Data.csproj +++ b/AntJob.Data/AntJob.Data.csproj @@ -37,7 +37,7 @@ - + diff --git a/AntJob.Extensions/AntJob.Extensions.csproj b/AntJob.Extensions/AntJob.Extensions.csproj index d07f05d..38bef70 100644 --- a/AntJob.Extensions/AntJob.Extensions.csproj +++ b/AntJob.Extensions/AntJob.Extensions.csproj @@ -43,7 +43,7 @@ - + diff --git a/AntJob.Server/AntJob.Server.csproj b/AntJob.Server/AntJob.Server.csproj index a8b1272..9c8d2d1 100644 --- a/AntJob.Server/AntJob.Server.csproj +++ b/AntJob.Server/AntJob.Server.csproj @@ -29,7 +29,7 @@ - + diff --git a/AntJob.Web/AntJob.Web.csproj b/AntJob.Web/AntJob.Web.csproj index a514b10..4341406 100644 --- a/AntJob.Web/AntJob.Web.csproj +++ b/AntJob.Web/AntJob.Web.csproj @@ -44,9 +44,9 @@ - - - + + + diff --git a/AntJob/AntJob.csproj b/AntJob/AntJob.csproj index 4970646..0ace732 100644 --- a/AntJob/AntJob.csproj +++ b/AntJob/AntJob.csproj @@ -49,9 +49,9 @@ - - - + + + diff --git a/AntJob/Scheduler.cs b/AntJob/Scheduler.cs index cd42b7b..928fb8c 100644 --- a/AntJob/Scheduler.cs +++ b/AntJob/Scheduler.cs @@ -47,11 +47,18 @@ protected override void Dispose(Boolean disposing) /// public void AddHandler() where T : Handler { - var services = ObjectContainer.Current; - var prv = ObjectContainer.Provider; - services.AddTransient(); + var prv = ServiceProvider; + if (prv == null) + { + var services = ObjectContainer.Current; + prv = ObjectContainer.Provider; + services.AddTransient(); + } + + // 马上实例化 + var handler = prv.GetService() ?? prv.CreateInstance(typeof(T)) as T; - Handlers.Add(prv.GetService()); + Handlers.Add(handler); } #endregion diff --git a/Samples/HisData/HisData.csproj b/Samples/HisData/HisData.csproj index c0297b2..c568f1f 100644 --- a/Samples/HisData/HisData.csproj +++ b/Samples/HisData/HisData.csproj @@ -16,7 +16,7 @@ - + diff --git a/Samples/HisWeb/HisWeb.csproj b/Samples/HisWeb/HisWeb.csproj index 9fffe89..db46c50 100644 --- a/Samples/HisWeb/HisWeb.csproj +++ b/Samples/HisWeb/HisWeb.csproj @@ -9,7 +9,7 @@ - +