I'm developing a middleware which I would like to have an optional dependency on a internal logging library. In another words, if MyLoggingService
is registered, great!, else, life goes on and ill log to console.
But by declaring public async Task Invoke(HttpContext httpContext, MyLoggingService logger)
, I get a runtime error saying that it was not registred. I tried setting a default value to null
but that didn't work. Also, because its a middleware, I can't overload the Invoke
method.
Is there a solution other than requesting the service collection and resolving the dependency myself?