Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KernelBase is implementing IServiceProvider.GetService incorrectly #376

Closed
lord-executor opened this issue Oct 25, 2020 · 0 comments
Closed
Assignees
Milestone

Comments

@lord-executor
Copy link
Contributor

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.

lord-executor added a commit to lord-executor/Ninject that referenced this issue Oct 25, 2020
scott-xu pushed a commit that referenced this issue Apr 17, 2022
* Fixing IServiceProvider.GetService implementation (fixes #376)

* Added a configuration option to restore the old behavior if necessary
@scott-xu scott-xu self-assigned this Apr 17, 2022
@scott-xu scott-xu added this to the 3.3.5 milestone Apr 17, 2022
scott-xu pushed a commit that referenced this issue May 1, 2022
* Fixing IServiceProvider.GetService implementation (fixes #376)

* Added a configuration option to restore the old behavior if necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants