ISEbd-21 Melnikov I. O. Lab Work 08 Base #26
@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user