Guidance for interfaces

Sep 19, 2008 at 9:58 PM
MEF is working like a charm, there is only one area I'm a wee bit fuzzy on and was wondering what the official guidance will be.   Does the host application distribute an interface library for third-parties to develop to/with?  Note: my ILogger interface references enum parameters which are also in the interface library.

In the my proof of concept (fully functional, code HERE) I have three solutions:  DebugLogger, MessageBoxLogger and the main application BasicWPFApp.  All three applications reference the same MEFContrib.Library.Interface project.   Both DebugLogger and MessageBoxLogger projects are configured to only copy their respective .DLL's to the Extensions folder (not the ComponentModel or MEFContrib.Library.Interface dlls which they have a reference to). 

Full source for the BaseWPFApp, minus using statements and xaml, follows below (Bootstrapper is in a MEFContrib.Library project):

public partial class App : Application, IMefApplication
{
    [Import("MainWindow")]
    public new Window MainWindow
    {
        get { return base.MainWindow; }
        set { base.MainWindow = value; }
    }
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        BootStrapper bootStrapper = new BootStrapper(this,
            new BootStrapperEventArgs(Assembly.GetExecutingAssembly()));
    }
    public void OnAddCatalog(ICollection<ComposablePartCatalog> catalogs)
    {
        catalogs.Add(new DirectoryPartCatalog("Extensions", true));
    }
}

 

[Export("MainWindow")]
public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }
    private ExportCollection<ILogger> _loggers = null;
    [Import(typeof(ILogger))]
    public ExportCollection<ILogger> Loggers
    {
        set { _loggers = value; }
    }

    public ILogger DebugLogger{
        get {
            return _loggers.Resolve<ILogger>("DebugLogger");
        }
    }
    public ILogger MessageBoxLogger {
        get {
            return _loggers.Resolve<ILogger>("MessageBoxLogger");
        }
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        DebugLogger.Log("Click",
            LogCategoryType.Debug, LogPriortyType.None);
    }
    private void button2_Click(object sender, RoutedEventArgs e)
    {
        MessageBoxLogger.Log("Click",
            LogCategoryType.Debug, LogPriortyType.None);
    }
}

Sep 20, 2008 at 9:14 PM
Hi Bill

Yes in MEF V1, a shared library is required which contains types that are common to the host and the client such as your ILogger interface defined above.

Regards
Glenn