You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the documentation of IServiceProvider, the method GetService is supposed to return null if there is no service object of the requested service type. KernelBase however delegates the call to the Get method which throws an exception in that case instead of delegating to the TryGet method which would be in line with the documentation.
This little quirk is the cause of some relatively weird and unnecessary workarounds when trying to integrate Ninject into a context like ASP.NET Core which mostly relies on the IServiceProvider interface. Effectively, one has to create a separate IServiceProvider implementation that wraps the kernel instead of just using the kernel directly.
As far as I can tell, that has been the expected behavior of the IServiceProvider from the very beginning and the Ninject implementation is just slightly off-spec.
The text was updated successfully, but these errors were encountered:
According to the documentation of
IServiceProvider
, the methodGetService
is supposed to returnnull
if there is no service object of the requested service type.KernelBase
however delegates the call to theGet
method which throws an exception in that case instead of delegating to theTryGet
method which would be in line with the documentation.This little quirk is the cause of some relatively weird and unnecessary workarounds when trying to integrate Ninject into a context like ASP.NET Core which mostly relies on the
IServiceProvider
interface. Effectively, one has to create a separateIServiceProvider
implementation that wraps the kernel instead of just using the kernel directly.As far as I can tell, that has been the expected behavior of the
IServiceProvider
from the very beginning and the Ninject implementation is just slightly off-spec.The text was updated successfully, but these errors were encountered: