First, I do not consider this question be the dup of these SO questions:
Should I always return IEnumerable<T> instead of IList<T>? and IEnumerable<T> as return type
As we all know ont of the main purposes of introducing several tiers is to decrease coupling.
We must define some interface for data access and our BL should not care about the details of DAL implementation. If mentioned interface returnes IEnumerable<T>
BL does not know whether it is just a static IEnumerable
or something that has deferred execution. At the same time this particular detail can affect perfromance considerably and requires different coding depending on the implementation.
Well, it is possible to call .ToList()
for each IEnumerable
in situations when we are going to iterate collection several times. But this decreases perfromance for static collections because of unnecessary new list instantiation.
So I'm trying to understand which approach is better.
More universal and potentially less performant vs More coupled-more performant.
I guess, there's no silver bullet but it could be other approaches I've missed.
IReadOnlyList<T>
. – Tuft