Search code examples
c#wcfiismef

Bootstrapper for MEF CompositionContainer in WCF website


I need to run a Bootstrapper / Init method to populate a MEF CompositionContainer in a website that hosts my WCF services. The website is hosted in IIS and only holds 2 .svc files that point to the service implementation in a different project. I don't want to make this website any bigger than it has to be. The Init method I want to run is shown below:

public static CompositionContainer Init()
{
    AggregateCatalog catalog = new AggregateCatalog();
    catalog.Catalogs.Add(new AssemblyCatalog(typeof(PlayerRepository).Assembly));
    CompositionContainer container = new CompositionContainer(catalog);

    return container;
}

Can this be done through the Web.config? Or is there a class I can add to the website that could perform this task. I can do this easy enough if I host the services in a Windows Service as I can call this in the On_Start().

Any help would be greatly appreciated!


Solution

  • I solved this by adding a Global.asax and calling my Init() method from the Application_Start(). This means only 1 extra file in the website.