ISEbd-21 Melnikov I. O. Lab Work 08 Base #26

Closed
Igor-Melnikov wants to merge 8 commits from lab8 into lab7
2 changed files with 49 additions and 0 deletions
Showing only changes of commit 77c46e739a - Show all commits

View File

@ -0,0 +1,21 @@
using BlacksmithWorkshopContracts.DI;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopFileImplement.Implements;
namespace BlacksmithWorkshopFileImplement
{
public class FileImplementationExtension : IImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<IManufactureStorage, ManufactureStorage>();
DependencyManager.Instance.RegisterType<IBackupInfo, BackupInfo>();
}
}
}

View File

@ -0,0 +1,28 @@
using BlacksmithWorkshopContracts.StoragesContracts;
namespace BlacksmithWorkshopFileImplement.Implements
{
public class BackupInfo : IBackupInfo
{
public List<T>? GetList<T>() where T : class, new()
{
var source = DataFileSingleton.GetInstance();
return (List<T>?)source.GetType().GetProperties()
.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))
?.GetValue(source);
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
var assembly = typeof(BackupInfo).Assembly;
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
{
return type;
}
}
return null;
}
}
}