Exporting IEnumerable<T> vs. Importing IEnumerable<T>

Dec 22, 2008 at 10:43 AM

Suppose we have the following exports and imports:

[Export]
T source1;

[Export]
T source2;

[Export]
IEnumerable<T> source3;

[Import]
IEnumerable<T> target;

What will the be the contents of the target import?

Developer
Dec 22, 2008 at 5:24 PM
The contents of target will be (source1, source2), it will not include anything from source3. Including individual items from source3, what we refer to as flattening the export, is not supported because it would destroy lazy loading. What I mean by that is in order for us to use source3 we would have to instantiate an instance of the type that holds source3 and pull on the collection in order to figure out how many items exist in that collection. This early instantiation is what kills our lazy loading. We do not have to do any early instantiation for source1 and source2 because we can figure out everything we need from the metadata.

We have explored adding the "Export flattening" feature a number of times and we always end up not being able to support it.
Developer
Dec 22, 2008 at 5:26 PM
As a followup if you did want to export collections then on the import side you would have to import a collection of collections and flatten yourself, for example:

[Export]
IEnumerable<T> source4

[Export]
IEnumerable<T> source5

[Import]
IEnumerable<IEnumerable<T>> target;