I am new to System.Action<T> and Lambda expression. Here is one case I would like to use.
using System;
using System.ComponentModel.Composition;
public class MyClass {
public static CompositionContainer Container = new CompositionContainer();
private void Initialize(Action<CompositonBatch> action) {}
public MyClass() {
CompositionBatch batch = null;
inititialize(x=> {
// create catalog instances: instance1 and instance2 as example
// ...
x.AddPart(instance1);
x.AddPart(instance2);
batch = x;
});
// at this point, will be batch be none-null value will parts added?
// the following code is composing batch to the container
Container.Compose(batch);
}
}
Basically, the method Initialize(Action<CompositionBatch> action) is used to initialize MEF catalog parts to a CompositionBatch instance, which adds all the import and export parts. After that, the batch is composed to the container to resolve all the DI mappings.
I am not sure if I use System.Action<T> and Lambda expression correctly here. Would x be created by Composition() CTOR on-fly in this example? Should I put anything in the method Initialize()? Or should I create a delegate as Initialize() instead(if so I think I still need to bind it to a method)?