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

MvcCoreServiceCollectionExtensions retrieves first registered service instead of last #5554

Closed
Eilon opened this issue Nov 21, 2016 · 3 comments
Assignees

Comments

@Eilon
Copy link
Member

Eilon commented Nov 21, 2016

This line:

https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs#L90

Per @danroth27 :

When you request a service from the built service provider it will give you the last service added, not the first one. This method should mimic the DI behavior.

This issue doesn't generally affect user scenarios today, because this method is used to extract the hosting environment service and there is typically only one of those. I hit this issue as part of my module prototyping when I added a new hosting environment for each module. The added hosting environment should override the existing one, but currently it doesn't because this method picks the first instead of the last. I'm working around this right now by simply removing the app hosting environment for each module and then replacing it with a new one.

@dougbu
Copy link
Member

dougbu commented Nov 21, 2016

Fix ready in #5540 but I'll get a PR out that builds on that and adds a test.

dougbu added a commit that referenced this issue Nov 23, 2016
dougbu added a commit that referenced this issue Dec 6, 2016
@dougbu
Copy link
Member

dougbu commented Dec 6, 2016

f32d0f2 and 48546db

@dougbu dougbu closed this as completed Dec 6, 2016
@dougbu
Copy link
Member

dougbu commented Dec 6, 2016

Thanks for f32d0f2 @danroth27 !

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

2 participants