I have one .NET Core MVC application that provides a dashboard to represent statistics and so on.
I would like to use this MVC application as a Middleware so that I can use it the same way than Hangfire, NSwag and so on.
So in my main project I would like to do the following:
- Import my NuGet package (the Dashboard MVC Application)
- app.UseDashboard(options...)
I already have a Middleware class inside my Dashboard MVC App with the following:
public static class JwtDashboardMiddleware
{
public static void UseMyDashboard(this IApplicationBuilder app)
{
// 1. Provide an endpoint(/ myDashboard)
app.Map("/myDashboard", app =>
app.Run(async (context) =>
{
string message = "Hello Middleware";
//2. This page contains a simple form, Submit the form to redirect to another for
await context.Response.BodyWriter.WriteAsync(Encoding.UTF8.GetBytes(message));
}));
}
}
I also created a NuGet Package with the Dashboard MVC App and it is working, but in the Main Application and also in the in the Dashboard MVC App it cannot access the Views and so on.
So from the Middleware inside the Dasboard MVC app how do I access the controllers and how do I integrate this with other MVC applications to achieve the points mentioned above?
Btw. I also tried to redirect to the controller view, but the view is just not accessible ? Do I need to compile the views to be included in the NuGet package or how does this work?
The main question is: How do I use my controllers and views inside the Middleware?