Я пытаюсь создать веб-сервис с использованием ASP.NET Core 2.1, где мне нужен сервис, чтобы иметь возможность регистрировать BaseControllers, загруженные из DLL через отражение. Однако я не могу найти, как зарегистрировать BaseController в конфигурации службы.
In Startup.cs
public class Startup
{
....
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
/// This now loads the base controllers located
/// within the dll's through reflection and the
/// BaseControllers are initialized as well
IList<ControllerBase> controllers = PluginLoader.Instance.GetControllers();
foreach (ControllerBase controllerBase in controllers)
{
/// Here I hope that I can add the controllerBase to services but
/// I just can't seem to find a way to do it. Is it even possible?
/// I'm thinking that builder.AddControllersAsServices() might be useful for something but just can't seem to get it right
}
}
}
У кого-нибудь есть какие-либо советы?