Skip to content

KernelBase is implementing IServiceProvider.GetService incorrectly #376

@lord-executor

Description

@lord-executor

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.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions