diff --git a/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj b/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj
index 4b0949c..24fc67c 100644
--- a/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj
+++ b/ConfectionaryBusinessLogic/ConfectioneryBusinessLogic.csproj
@@ -17,4 +17,8 @@
+
+
+
+
diff --git a/ConfectionaryBusinessLogic/ImplementationBusinessLogicExtension.cs b/ConfectionaryBusinessLogic/ImplementationBusinessLogicExtension.cs
new file mode 100644
index 0000000..cf5a010
--- /dev/null
+++ b/ConfectionaryBusinessLogic/ImplementationBusinessLogicExtension.cs
@@ -0,0 +1,39 @@
+using ConfectioneryBusinessLogic.BusinessLogics;
+using ConfectioneryBusinessLogic.MailWorker;
+using ConfectioneryBusinessLogic.OfficePackage.Implements;
+using ConfectioneryBusinessLogic.OfficePackage;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.DI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryBusinessLogic
+{
+ public class ImplementationBusinessLogicExtension : IImplementationBusinessLogicExtension
+ {
+ public int Priority => 0;
+
+ public void RegisterServices()
+ {
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+
+ DependencyManager.Instance.RegisterType(true);
+
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ }
+ }
+}
diff --git a/Confectionery/Program.cs b/Confectionery/Program.cs
index 5349e2f..08d9a81 100644
--- a/Confectionery/Program.cs
+++ b/Confectionery/Program.cs
@@ -60,23 +60,6 @@ namespace ConfectioneryView
option.AddNLog("nlog.config");
});
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
-
- DependencyManager.Instance.RegisterType(true);
-
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
- DependencyManager.Instance.RegisterType();
-
DependencyManager.Instance.RegisterType();
DependencyManager.Instance.RegisterType();
DependencyManager.Instance.RegisterType();
diff --git a/ConfectioneryContracts/DI/DependencyManager.cs b/ConfectioneryContracts/DI/DependencyManager.cs
index f524768..a35a967 100644
--- a/ConfectioneryContracts/DI/DependencyManager.cs
+++ b/ConfectioneryContracts/DI/DependencyManager.cs
@@ -27,13 +27,16 @@ namespace ConfectioneryContracts.DI
///
public static void InitDependency()
{
- var ext = ServiceProviderLoader.GetImplementationExtensions();
- if (ext == null)
+ var extList = ServiceProviderLoader.GetImplementationExtensions();
+ foreach(var ext in extList)
{
- throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
+ if (ext == null)
+ {
+ throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
+ }
+ // регистрируем зависимости
+ ext.RegisterServices();
}
- // регистрируем зависимости
- ext.RegisterServices();
}
///
diff --git a/ConfectioneryContracts/DI/IImplementationBusinessLogicExtension.cs b/ConfectioneryContracts/DI/IImplementationBusinessLogicExtension.cs
new file mode 100644
index 0000000..b963103
--- /dev/null
+++ b/ConfectioneryContracts/DI/IImplementationBusinessLogicExtension.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryContracts.DI
+{
+ ///
+ /// Интерфейс для индентификации и отделения загрузки бизнес-логики от загрузки хранилищ
+ ///
+ ///
+ public interface IImplementationBusinessLogicExtension : IImplementationExtension { }
+}
diff --git a/ConfectioneryContracts/DI/ServiceProviderLoader.cs b/ConfectioneryContracts/DI/ServiceProviderLoader.cs
index 017dd9c..dca5bf3 100644
--- a/ConfectioneryContracts/DI/ServiceProviderLoader.cs
+++ b/ConfectioneryContracts/DI/ServiceProviderLoader.cs
@@ -13,33 +13,43 @@ namespace ConfectioneryContracts.DI
/// Загрузка всех классов-реализаций IImplementationExtension
///
///
- public static IImplementationExtension? GetImplementationExtensions()
+ public static List GetImplementationExtensions()
{
- IImplementationExtension? source = null;
+ // Список типов, по каждому из которых, должна быть выбрана наиболее приоритетная реализация
+ // IImplementationExtension должен быть последним, поскольку все классы реализации, наследуются от него и являются им в частности
+ Type[] handledTypes =
+ {
+ typeof(IImplementationBusinessLogicExtension),
+ typeof(IImplementationExtension)
+ };
+ var result = handledTypes.Select(x => (IImplementationExtension?)null).ToList();
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
Assembly asm = Assembly.LoadFrom(file);
foreach (var t in asm.GetExportedTypes())
{
- if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
+ for (var i = 0; i < handledTypes.Length; i++)
{
- if (source == null)
+ if (t.IsClass && handledTypes[i].IsAssignableFrom(t))
{
- source = (IImplementationExtension)Activator.CreateInstance(t)!;
- }
- else
- {
- var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
- if (newSource.Priority > source.Priority)
+ if (result[i] == null)
{
- source = newSource;
+ result[i] = (IImplementationExtension)Activator.CreateInstance(t)!;
+ }
+ else
+ {
+ var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
+ if (newSource.Priority > result[i].Priority)
+ {
+ result[i] = newSource;
+ }
}
}
}
}
}
- return source;
+ return result;
}
private static string TryGetImplementationExtensionsFolder()