tags:

views:

120

answers:

1

Hi all I need to implement a very small plugin architecture.I am new to MEF so even simple things become complex. Lets assume I have 2 dlls Client(Executing Assembly) and Server Within Server I have a folder called "Plugins"

Usually I create a "Plugins" folder in the bin directory of the executingAssembly and all works with this piece of code,How Can I make it work if the plugin folder is in the Server?

    private void LoadPlugins(string folder)
    {
        AggregateCatalog catalog=new AggregateCatalog();
        catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
        catalog.Catalogs.Add(new DirectoryCatalog(folder));
        CompositionContainer container =new CompositionContainer(catalog);
        container.ComposeParts(this);
    }

Any Suggestions?

PS The plugins will only be used to process logic within the server they are not used at all by the client

+2  A: 

Do you want to download the plugins from the server and use them in your client app? If so, you could download them to a specific path and create the catalog over that path. Or you could download each assembly, load it with Assembly.Load() or a similar method, and create an AssemblyCatalog over it.

Daniel Plaisted
No The plugins will only be used to process logic within the server they are not used at all by the client.Any snippet would be very appreciated as new to mef.Thanks for your time
@devnet247 OK, what type of server is this? ASP.NET?
Daniel Plaisted
Daniel.I really appreciate your help as I need to have it done by monday.It's not asp.net .Not sure if relevant at all though.Client it's WPF and the Plugins will be on another dll where we keep the business logic and Data access. The main problem again is unless the plugins sits on a directory inside the (Client)executing assembly it seems there is no way to do it.I need the ability to place the plugins in a folder in any location and still pick it up.thanks
@devnet247 You can create a DirectoryCatalog for any folder, it doesn't need to be under the path to the executable. However, in .NET there can be issues loading assemblies from outside the probing path. See the "Assembly Loading Issues" section of this blog post for a summary: http://blogs.msdn.com/b/dsplaisted/archive/2010/07/13/how-to-debug-and-diagnose-mef-failures.aspx
Daniel Plaisted
Daniel thanks for your quick reply.Does it mean you have to place the plugin folder inside the executing assembly and there is no code that will locate where in the folder structure my plugins folder is located. What about "Mef Hosting" in a class library.What does "Hosting" mean? Does it mean I can start MEF whenever I like and put the "plugin" folder whenever I like?thanks .Reading the link now.Thanks