Рефактор
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 4m6s

This commit is contained in:
2025-10-15 00:03:31 +03:00
parent e0fffbd4b5
commit ad5576958f
3 changed files with 23 additions and 22 deletions

View File

@@ -20,6 +20,7 @@ public class ProxyController(ModeusService modeusService, ILogger<ScheduleContro
/// <response code="200">Возвращает расписание</response>
/// <response code="429">Слишком много запросов</response>
[HttpPost]
[Route("events/search")]
public async Task<IActionResult> Post([FromBody] ModeusScheduleRequest request)
{
string? schedule;

View File

@@ -9,12 +9,12 @@ using SfeduSchedule.Services;
namespace SfeduSchedule.Controllers;
[ApiController]
[Route("api/[controller]")]
[Route("api/schedule")]
[EnableRateLimiting("throttle")]
public class ScheduleController(ModeusService modeusService, ILogger<ScheduleController> logger) : ControllerBase
{
/// <summary>
/// Получить расписание по пользовательскому запросу.
/// [УСТАРЕЛО] Получить расписание по пользовательскому запросу.
/// </summary>
/// <param name="request">Объект запроса, содержащий параметры фильтрации расписания.</param>
/// <returns>Список событий расписания.</returns>
@@ -41,7 +41,7 @@ public class ScheduleController(ModeusService modeusService, ILogger<ScheduleCon
}
/// <summary>
/// Поиск аудиторий по пользовательскому запросу.
/// [УСТАРЕЛО] Поиск аудиторий по пользовательскому запросу.
/// </summary>
/// <param name="request">Объект запроса, содержащий параметры фильтрации аудиторий.</param>
/// <returns>Список аудиторий.</returns>

View File

@@ -18,20 +18,26 @@ public static class PluginLoader
foreach (var file in Directory.EnumerateFiles(pluginsDir, "*.plugin.dll", SearchOption.AllDirectories))
{
var path = Path.GetFullPath(file);
var alc = new PluginLoadContext(path);
var asm = alc.LoadFromAssemblyPath(path);
try
{
var path = Path.GetFullPath(file);
var alc = new PluginLoadContext(path);
var asm = alc.LoadFromAssemblyPath(path);
// Ищем реализацию IPlugin
var pluginType = asm
.GetTypes()
.FirstOrDefault(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface);
var pluginType = asm
.GetTypes()
.FirstOrDefault(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface);
if (pluginType is null)
continue;
if (pluginType is null)
continue;
var instance = (IPlugin)Activator.CreateInstance(pluginType)!;
result.Add(new LoadedPlugin(instance, asm, alc));
var instance = (IPlugin)Activator.CreateInstance(pluginType)!;
result.Add(new LoadedPlugin(instance, asm, alc));
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка загрузки плагина {file}: {ex.Message}");
}
}
return result;
@@ -39,15 +45,9 @@ public static class PluginLoader
}
// Отдельный контекст загрузки для изоляции зависимостей плагина
public sealed class PluginLoadContext : AssemblyLoadContext
public sealed class PluginLoadContext(string pluginMainAssemblyPath) : AssemblyLoadContext(isCollectible: true)
{
private readonly AssemblyDependencyResolver _resolver;
public PluginLoadContext(string pluginMainAssemblyPath)
: base(isCollectible: true)
{
_resolver = new AssemblyDependencyResolver(pluginMainAssemblyPath);
}
private readonly AssemblyDependencyResolver _resolver = new(pluginMainAssemblyPath);
// Разрешаем управляемые зависимости плагина из его папки.
// Возвращаем null, чтобы отдать решение в Default ALC для общих сборок (например, SfeduSchedule.Abstractions).