Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Add interface to allow container implementors to expose a more native service lookup for required services #378

Closed
davidfowl opened this issue Mar 8, 2016 · 4 comments
Assignees
Milestone

Comments

@davidfowl
Copy link
Member

We're going to add this interface to allow container implementors to directly call into their intrinsics without checking for existence and returning null. It also lets GetRequiredService fail with container specific diagnostics instead of our own. This interface would be optional and we would light it up here:

https://github.com/aspnet/DependencyInjection/blob/dev/src/Microsoft.Extensions.DependencyInjection.Abstractions/ServiceProviderExtensions.cs#L38

If the interface exists, we would call it directly, otherwise we'll use the existing behavior.

See the original discussion here #238.

public interface IGetRequiredServiceAware
{
   object GetRequiredService(Type serviceType);
}

Name suggestions are welcome.

/cc @jeremydmiller

@jeremydmiller
Copy link

Thank you. This will make it easier for StructureMap users to correct common registration problems that could be hidden behind the previously default TryGetInstance<T> mechanics.

Consider the case where a users is using some kind of conventional scanning to register types, and it finds two different concrete types of IService and registers each. In StructureMap, we will not choose either the first or last registration as the "default", in the case of multiples you have to explicitly choose one or the other. In the case of asking for IService through IContainer.GetInstance<IService>(), StructureMap will tell you it has no default because more than one is registered, with a complete listing of each. That's a common problem in SM usage and one that would be much easier to solve for users w/ this new GetRequiredService() feature.

@davidfowl davidfowl changed the title Add interface to allow container implementors to optimize service lookup Add interface to allow container implementors to expose a more native service lookup for required services Mar 9, 2016
@davidfowl
Copy link
Member Author

/cc @dadhi @seesharper @tillig @khellang

@khellang
Copy link
Contributor

khellang commented Mar 9, 2016

Nice! 👍

kichalla added a commit that referenced this issue Mar 11, 2016
[Fixes ##378] Add interface to allow container implementors to expose a more native service lookup for required services
kichalla added a commit that referenced this issue Mar 14, 2016
[Fixes ##378] Add interface to allow container implementors to expose a more native service lookup for required services
@kichalla
Copy link
Member

4f423f0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants