Why middleware in ASP.NET Core requires specific semantics, but not an interface?

The Invoke method is flexible and you can ask for additional parameters. ASP.NET will inject the additional parameters using the application’s service configuration.

public async Task Invoke(HttpContext ctx, 
                         IHostingEnvironment host,
                         ISomethingElse service)
    // ...

C# interface definitions can’t provide this flexibility in a nice way.

Leave a Comment