Hooking up with the service collection
Since we’re leveraging ServiceProvider to create instances, and since its default behavior is to have everything explicitly registered with it, it might not have a registration for the concrete type we asked.
In Chapter 10, Convention over Configuration, you did an implementation for discovering the relationship between interfaces and implementations according to a convention. We can extend this thinking and say that it should be possible to resolve classes themselves according to their type.
To do this, we leverage more reflection metadata to filter out the different types we are not interested in.
In Chapter 10, Convention over Configuration, you created something called Service CollectionExtensions. We want to make use of this here as well, but we also want to add some additional functionality. Move the file into the shared Fundamentals project.
Open the ServiceCollectionExtensions class and add the following:
public static...