|
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System;
namespace BaseLibrary
{
public abstract class MefWorkflowProvider : IDisposable
{
/// <summary>
/// MEF composition Container
/// </summary>
protected CompositionContainer container { get; set; }
public CompositionContainer Container { get { return container; } }
public MefWorkflowProvider(bool useTestServices = false)
{
RegisterServices(useTestServices);
}
/// <summary>
/// Register the services in the catalog
/// </summary>
/// <param name="useTestServices">Should we discover imports/exports for testomg</param>
private void RegisterServices(bool useTestServices = false)
{
var aggregateCatalog = new AggregateCatalog();
var coreCatalog = RegisterCoreCatalogs();
var catalog = useTestServices ? RegisterTestCatalogs() : RegisterNormalCatalogs();
// create the catalogs from the derived type
if (coreCatalog != null)
aggregateCatalog.Catalogs.Add(coreCatalog);
if (catalog != null)
aggregateCatalog.Catalogs.Add(catalog);
// compose the container
container = new CompositionContainer(aggregateCatalog);
}
protected abstract ComposablePartCatalog RegisterTestCatalogs();
protected abstract ComposablePartCatalog RegisterCoreCatalogs();
protected abstract ComposablePartCatalog RegisterNormalCatalogs();
public void Dispose()
{
container.Dispose();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am Gareth, working in the book industry specializing in EDI and B2B integration. Starting out as a child bashing out programs on the old commodore 64, I have since progressed from VB6 through the .net framework and loving c#, wf, wpf and where these are heading... hoping one day to have the excuse to play with silverlight.