To make service discoverable, implement ISelfHostingConfiguration inteface and mark class using ExportSelfHostingConfiguration attribute.

[ExportSelfHostingConfiguration(typeof(SampleService))]
public class SelfHostingConfiguration : ISelfHostingConfiguration
{
    // implementation here
}


SelfHostingContainer will export marked configurations and instantiate service hosts for target services.

// create catalog and composition container
var catalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory);
var container = new CompositionContainer(catalog);
using (var serviceContainer = new SelfHostingContainer(container))
{
    serviceContainer.Open();
    Console.WriteLine("Press RETURN to close hosts and exit...");
    Console.ReadLine();
}

Last edited Jan 9, 2014 at 11:36 PM by kovalikp, version 3