We're currently developping a dynamic system which need to load some extensions at runtime.
An extension is build on the same architecture that MVC app, which means a controller folder, with classes that ends with Controller, associated Views and ViewComponents that are located in /View/ControllerName, and related models.
It is not possible to add this project as reference to the project, so I created a middleware that load them at runtime :
foreach (var item in extensions)
{
Assembly.LoadFrom($@"extensions\{item.Name}.dll");
}
So far so good, they are loaded on runtime. But, when I try to access a route that is created in one of extension's controller, WebSite gives me a 404 response.
I tried to add the extension as reference and it works well, so this is not an issue inside my extension.
How can I manage to register my dll's controller into the MVC main site ?
This is NOT ASP MVC 4, this is ASP Core, therefore it seems that this answer is not valid : asp.net mvc put controllers into a separate project
Although Dependency Injection could be a solution, I don't found any solution to make my extension register services for itself (and it's complicated for extensions creators).
My routing for extensions is defined Controller side :
[Route("[controller]/[action]")]
public class LotteryController : Controller { ... }
On my Startup.cs, I've kept the default route actually :
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
The fact is, I want my extension to enable route : http://localhost/Lottery/Index
And it gives me a blank page. My current Index action, for testing purpose, is
// GET Index
public IActionResult Index()
{
return Content("From extension");
//return View();
}
And here's my extension project hierarchy