Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Lamar/IoC/Enumerables/ArrayInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ protected override IEnumerable<Instance> createPlan(ServiceGraph services)
}
else
{
Elements = services.FindAll(typeof(T));
// MS DI's IServiceProvider.GetServices(T) (and by extension T[] resolution) returns
// only non-keyed registrations; keyed registrations are looked up explicitly via
// GetKeyedService(T, key). Match that here so a keyed-mirror registration of the
// same service type doesn't end up as a T[] element. Otherwise inlining the
// mirror's Singleton via QuickResolve invokes the mirror's factory, which calls
// sp.GetServices(T) again and recursively re-enters codegen — stack overflow.
Elements = services.FindAll(typeof(T)).Where(x => !x.IsKeyedService).ToArray();
}

return Elements;
Expand Down
8 changes: 7 additions & 1 deletion src/Lamar/IoC/Enumerables/ListInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ protected override IEnumerable<Instance> createPlan(ServiceGraph services)
}
else
{
Elements = services.FindAll(typeof(T));
// MS DI's IServiceProvider.GetServices(T) returns only non-keyed registrations;
// keyed registrations are looked up explicitly via GetKeyedService(T, key). Match
// that here so a keyed-mirror registration of the same service type doesn't end up
// as an IEnumerable<T> element. Otherwise inlining the mirror's Singleton via
// QuickResolve invokes the mirror's factory, which calls sp.GetServices(T) again
// and recursively re-enters ListInstance/ArrayInstance code-gen — stack overflow.
Elements = services.FindAll(typeof(T)).Where(x => !x.IsKeyedService).ToArray();
}

return Elements;
Expand Down
Loading