Wouterdek/NodeNetwork

[Demo] Calculator Example implemented using MEF plugins

evilC opened this issue · 5 comments

evilC commented

I took the calculator example, and have re-implemented it using MEF - each node (Sum, Product etc) is a separate assembly
https://github.com/evilC/NodeNetworkMefCalculator

It should all be pretty idiot-proof - ie Build Events are used to copy all the plugins into the target folder for the GUI, so you should be able to just clone and hit F5, and it should work.

So far, have only implemented Sum and Product, hopefully the others should work too.

For now, the export type is NodeViewModel, not sure if that's the best thing to be using
This was largely as a learning exercise for myself, am very open to any suggestions for improvements or PRs
Am also willing to merge it into the NodeNetwork codebase if you desire

As a further learning exercise, I may see if the Editors (eg IntegerValueEditorViewModel) can be implemented as MEF plugins too

Sounds cool! Seems like your repo is private though, because I get a 404 when I click the link.

evilC commented

D'oh, it's public now

evilC commented

Update - I noticed that you can only add one of each plugin :(
I guess this is to do with the PartCreationPolicy - I tried marking the exports with CreationPolicy.NonShared but it does not seem to fix it. Any ideas?

Unfortunately, I don't have any experience with MEF, so I can't help you there.

evilC commented

OK I figured it out.
Each plugin was exporting itself, whereas what I needed to do was have each plugin export a factory which could be used to create new instances of itself.
So what I was doing was

            var loader = new GenericMefPluginLoader<NodeViewModel>("Plugins\\Nodes");
            foreach (var plugin in loader.Plugins)
            {
                ListViewModel.AddNodeType(() => plugin.Value);
            }

Whereas I needed to be doing

            var loader = new GenericMefPluginLoader<NodePluginFactory>("Plugins\\Nodes");
            foreach (var plugin in loader.Plugins)
            {
                ListViewModel.AddNodeType(() => plugin.Value.CreatePlugin());
            }