© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
21 replies
CrosRoad95

❔ IEnumerable and dependency injection

if i want to loop enumerable from DI multiple times
var foos = services.GetRequiredService<IEnumerable<Foo>>(); // add .ToList()?
foreach(foo in foos) {}
foreach(foo in foos) {}
foreach(foo in foos) {}
var foos = services.GetRequiredService<IEnumerable<Foo>>(); // add .ToList()?
foreach(foo in foos) {}
foreach(foo in foos) {}
foreach(foo in foos) {}

is it better to first get list? My concern is that DI will look for "Foo" multiple times even if it isn't needed
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

xUnit and Dependency Injection
C#CC# / help
15mo ago
Dependency injection
C#CC# / help
6mo ago
✅ Dependency injection
C#CC# / help
2y ago
❔ Dependency Injection
C#CC# / help
3y ago