From 65b2573766bbc21ec30f87c435aa68dedda6e29c Mon Sep 17 00:00:00 2001 From: fanliang11 <137629448@qq.com> Date: Fri, 26 Apr 2024 20:23:56 +0800 Subject: [PATCH] Fix duplicate registration module Fix duplicate registration module --- .../ContainerBuilderExtensions.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Surging.Core/Surging.Core.CPlatform/ContainerBuilderExtensions.cs b/src/Surging.Core/Surging.Core.CPlatform/ContainerBuilderExtensions.cs index 746276bb..a46790a1 100644 --- a/src/Surging.Core/Surging.Core.CPlatform/ContainerBuilderExtensions.cs +++ b/src/Surging.Core/Surging.Core.CPlatform/ContainerBuilderExtensions.cs @@ -654,16 +654,19 @@ public static IServiceBuilder RegisterModules(this IServiceBuilder builder, para { GetAbstractModules(moduleAssembly).ForEach(p => { - services.RegisterModule(p); - if (packages.ContainsKey(p.TypeName)) - { - var useModules = packages[p.TypeName]; - if (useModules.AsSpan().IndexOf(p.ModuleName) >= 0) - p.Enable = true; - else - p.Enable = false; - } - _modules.Add(p); + if (!_modules.Any(m => p.ModuleName == m.ModuleName)) + { + services.RegisterModule(p); + if (packages.ContainsKey(p.TypeName)) + { + var useModules = packages[p.TypeName]; + if (useModules.AsSpan().IndexOf(p.ModuleName) >= 0) + p.Enable = true; + else + p.Enable = false; + } + _modules.Add(p); + } }); } builder.Services.Register(provider => new ModuleProvider(