I would like to screw the plug-in places in order to explicitly separate the applied logic from the system logic.

I looked at the two main options out of the box - MAF and MEF. The second one looks much simpler and more intuitive; I didn’t understand how to make plug-ins composite.

I am writing a site parser, respectively - on a plugin on a site or even on a couple of sites at once. The question arises - is it possible to arrange the requirements like that?

Those. when loading a conditional ISite implementation, ISite need to find the corresponding ILogin and INHibernateMapping . One class, as described in simple examples, does not suit me, I have at least three of them for a valid entity. Can I describe such dependencies in MEF in general, or do I have to create some kind of common IPlugin interface, which will contain all the related interfaces and use import / export only for the common IPlugin interface?

UPD: the main case - when all the necessary interfaces are still implemented in one assembly. If possible - in different.

    1 answer 1

    I decided to combine all the dependencies into one interface to make it easier to work with it. Conditionally something like this:

      public interface IPlugin { string Name { get; } System.Reflection.Assembly Assembly { get; } System.Type LoginType { get; } Services.Setting GetSettings(); } 

    Implementations in plugins are sufficient to mark with an attribute:

      using System.ComponentModel.Composition; [Export(typeof(IPlugin))] 

    Well and the main thing for the sake of what I was busy loading with validation:

     private static IEnumerable<IPlugin> GetPluginsFrom(string path) { if (Directory.Exists(path)) { try { var result = new List<IPlugin>(); var container = new CompositionContainer(new DirectoryCatalog(path)); var ione = typeof (IOne); var itwo = typeof (ITwo); foreach (var plugin in container.GetExportedValues<IPlugin>()) { try { if (!ione.IsAssignableFrom(plugin.OneType)) throw new Exception($"Type in property {nameof(plugin.OneType)} of " + $"type {plugin.GetType()} must be implement {ione} interface."); if (!itwo.IsAssignableFrom(plugin.LoginType)) throw new Exception($"Type in property {nameof(plugin.LoginType)} of " + $"type {plugin.GetType()} must be implement {itwo} interface."); result.Add(plugin); } catch (Exception e) { Log.Exception(e); } } return result; } catch (Exception ex) { Log.Exception(ex, string.Format("Plugins from {0} cannot be loaded.", path)); } } return Enumerable.Empty<IPlugin>(); } 
    • Any comment would be what is wrong. I'm still in the process of writing more, I'm not sure that it is convenient at all. - Monk