This project has moved. For the latest updates, please go here.

Compose parts but postpone the creation of the parts

Oct 9, 2012 at 8:45 PM

Hi All

As explained in the question here: I'm trying to build an application that consists of a host and multiple task processing clients. In the linked question Kevin helpfully provided me with suggestions on how to discover and serialize part definitions so that I could store those definitions without having to have the actual runtime type loaded.

The next step I want to achieve (or next two steps really) is that I want to split the composition of parts from the actual creation and connection of the objects (represented by those parts). So if I have a set of parts then I would like to be able to do the following thing (in pseudo-code):

public sealed class Host
    public CreationScript Compose()
        CreationScript result;
        var container = new DelayLoadCompositionContainer(
            s => result = s);
        return script;

    public static void Main()
        var script = Compose();

        // Send the script to the client application

// Lives inside other application
public sealed class Client
    public void Load(CreationScript script)
        var container = new ScriptLoader(script);

    public static void Main(string scriptText)
        var script = new CreationScript(scriptText);

So that way I can compose the parts in the host application, but actually load the code and execute it in the client application. The goal is to put all the smarts of deciding what to load in one location (the host) while the actual work can be done anywhere (by the clients).

Now my question is if there are any bits in MEF that would allow me to implement this kind of behaviour. If so where do I need to look and if not what would be the best way of implementing this.