Mochalov D.V. LabWork08_Hard #16

Closed
b0n3l3sS wants to merge 15 commits from LabWork08_Hard into LabWork07_Hard
Showing only changes of commit 441f2217c8 - Show all commits

View File

@ -9,20 +9,16 @@ namespace LawFirmContracts.DI
{
public class ServiceProviderLoader
{
/// <summary>
/// Загрузка всех классов-реализаций IImplementationExtension
/// </summary>
/// <returns></returns>
public static List<IImplementationExtension?> GetImplementationExtensions()
{
// Список типов, по каждому из которых, должна быть выбрана наиболее приоритетная реализация
// IImplementationExtension должен быть последним, поскольку все классы реализации, наследуются от него и являются им в частности
Type[] types =
{
typeof(ILogicImplementationExtension),
typeof(IImplementationExtension)
};
var trueTypes = types.Select(x => (IImplementationExtension?)null).ToList();
var endTypes = new IImplementationExtension?[types.Length];
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
@ -33,23 +29,23 @@ namespace LawFirmContracts.DI
{
if (t.IsClass && types[i].IsAssignableFrom(t))
{
if (trueTypes[i] == null)
if (endTypes[i] == null)
{
trueTypes[i] = (IImplementationExtension)Activator.CreateInstance(t)!;
endTypes[i] = (IImplementationExtension)Activator.CreateInstance(t)!;
}
else
{
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
if (newSource.Priority > trueTypes[i].Priority)
if (newSource.Priority > endTypes[i].Priority)
{
trueTypes[i] = newSource;
endTypes[i] = newSource;
}
}
}
}
}
}
return trueTypes;
return endTypes.ToList();
}
private static string TryGetImplementationExtensionsFolder()