Adding custom middleware not working when using IMiddleware
You're using factory-based middleware. As described in those docs, you've missed an important step:
... the IMiddlewareFactory instance registered in the container is used to resolve the IMiddleware implementation instead of using the convention-based middleware activation logic. The middleware is registered as a scoped or transient service in the app's service container.
In your case, that registration would look something like this:
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddTransient<RequestCultureMiddleware>();
}
I'm sure this problem has been solved long ago after 5 months, but I'm writing this advice just in case.
The problem is the "InvokeAsync" method of your custom middleware program is not be executed even though you built in it in "Configure" method of Startup.
I had the same problem the other day and solved it by, but I putting built in code right before the app.UseEndpoints method.
in your case
app.UseAuthorization();
app.UseRequestCulture(); // <- this way.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
By the way, if you put it after the app.UseEndpoints method, the constructor will be called, but the InvokeAsync method will not be executed.