C#C
C#4y ago
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) {}

is it better to first get list? My concern is that DI will look for "Foo" multiple times even if it isn't needed
Was this page helpful?