this is my first question so please do not judge strictly
I'm trying to understand how Middleware receives parameters from Configure method in Startup class.
Here is the code of Middleware class:
public class LocationMiddleware
{
private RequestDelegate next;
private MessageOptions options;
public LocationMiddleware(RequestDelegate nextDelegate,IOptions<MessageOptions> opts)
{
next = nextDelegate;
options = opts.Value;
}
public async Task Invoke(HttpContext context)
{
if (context.Request.Path=="/location")
{
await context.Response.WriteAsync($"{options.CityName}, {options.CountryName}");
}
else
{
await next(context);
}
}
}
Constructor of this class takes 2 parameters RequestDelegate and IOptions<MessageOptions>
But when calling a method UseMiddleware in Startup class no parameters are being sent in this line app.UseMiddleware<LocationMiddleware>();
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMiddleware<LocationMiddleware>();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
So my question is how middleware class receives this parameters?