фиксируем прибыль
This commit is contained in:
parent
a321251734
commit
a937d4b26c
@ -20,12 +20,11 @@ namespace FlowerShopContracts.DI
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_manager ==
|
||||
null) { lock (_locjObject) { _manager = new DependencyManager(); } }
|
||||
return
|
||||
_manager;
|
||||
if (_manager ==null) { lock (_locjObject) { _manager = new DependencyManager(); } }
|
||||
return _manager;
|
||||
}
|
||||
}
|
||||
// инициализация библиотек, в которых идут установки зависимостей
|
||||
public static void InitDependency()
|
||||
{
|
||||
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
||||
@ -33,6 +32,7 @@ namespace FlowerShopContracts.DI
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компонент для загрузки зависимостей по модулям");
|
||||
}
|
||||
// регистрация зависимостей
|
||||
ext.RegisterServices();
|
||||
}
|
||||
public void AddLogging(Action<ILoggingBuilder> configure) =>
|
||||
|
@ -12,28 +12,26 @@ namespace FlowerShopContracts.DI
|
||||
public static IImplementationExtension? GetImplementationExtensions()
|
||||
{
|
||||
IImplementationExtension? source = null;
|
||||
var files =
|
||||
Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll",
|
||||
SearchOption.AllDirectories);
|
||||
foreach (var file in files.Distinct())
|
||||
// массив строк, представляющий пути ко всем файлам длл в этой директории и подпапках
|
||||
var files =Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll",SearchOption.AllDirectories);
|
||||
foreach (var file in files.Distinct())// каждый файл будет рассмотрен только один раз
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
Assembly asm = Assembly.LoadFrom(file);// загрузка сборки
|
||||
// проходит по всем типам экспортированным из текущей сборки
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
if (t.IsClass &&
|
||||
typeof(IImplementationExtension).IsAssignableFrom(t))
|
||||
// если тип является классом и реализует интерфейс ИИЕ
|
||||
if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
source =
|
||||
(IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
// создаем экземпляр этого класса
|
||||
source = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource =
|
||||
(IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority >
|
||||
source.Priority)
|
||||
{ // сравнение приоритетов текущего и нового экземпляра
|
||||
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority > source.Priority)
|
||||
{
|
||||
source = newSource;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -12,6 +12,7 @@ namespace FlowerShopDatabaseImplement
|
||||
public class DatabaseImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 2;
|
||||
// регистрация зависимостей в контейнере dependency manager
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage,ClientStorage>();
|
||||
|
BIN
ImplementationExtensions/FlowerShopContracts.dll
Normal file
BIN
ImplementationExtensions/FlowerShopContracts.dll
Normal file
Binary file not shown.
BIN
ImplementationExtensions/FlowerShopDataModels.dll
Normal file
BIN
ImplementationExtensions/FlowerShopDataModels.dll
Normal file
Binary file not shown.
BIN
ImplementationExtensions/FlowerShopDatabaseImplement.dll
Normal file
BIN
ImplementationExtensions/FlowerShopDatabaseImplement.dll
Normal file
Binary file not shown.
BIN
ImplementationExtensions/FlowerShopFileImplement.dll
Normal file
BIN
ImplementationExtensions/FlowerShopFileImplement.dll
Normal file
Binary file not shown.
BIN
ImplementationExtensions/FlowerShopListImplement.dll
Normal file
BIN
ImplementationExtensions/FlowerShopListImplement.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user