Register components using ReflectionContext after TypeCatalog creation

Mar 1, 2011 at 8:44 PM
Edited Mar 1, 2011 at 8:47 PM

Is it possible to add new type in the RegistrationBuilder after the TypeCatalog has been created?

What I would like to do is to access the ReflectionContext of a TypeCatalog and register types any time in the lifetime of the application (after the TypeCatalog has been created).

(see the lines with bold)

[TestMethod]
public void ExportInterfaceWithTypeOf1()
{
    var ctx = new RegistrationBuilder();
    ctx.OfType<CFoo>().Export<IFoo>();
    var catalog = new TypeCatalog(Helpers.GetEnumerableOfTypes(typeof(CFoo)), ctx);
    Assert.IsTrue(catalog.Parts.Count() != 0);

    var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
    var importer = new FooImporter();
    container.SatisfyImportsOnce(importer);

   Assert.IsNotNull(importer.fooImporter, "fooImporter not set!");

    ctx.OfType<CFoo2>().Export<IFoo>((c) => c.Named("concreteA"));     
    ctx.OfType<CFoo3>().Export<IFoo>((c) => c.Named("concreteB"));

   Assert.IsNotNull(container.GetExportedValue<IFoo>("concreteA"));
}