none
How to add a RegistrationBuilder to a catalog RRS feed

  • Question

  • How do I add a registrationBuilder to a container?

    ar registrationBuilder = new RegistrationBuilder();
    registrationBuilder.ForTypesDerivedFrom<IMyClass>().Export<IMyClass>();
    var catalog = new AggregateCatalog(
                            new DirectoryCatalog("."),
                            new AssemblyCatalog(Assembly.GetExecutingAssembly()));
    catalog.Catalogs.Add(Assembly.GetExecutingAssembly(), registrationBuilder);

    Thanks
    Friday, August 23, 2013 6:00 PM

Answers

  • I fixed my problem.  The type I needed was in a different assembly.

                var catalog = new AggregateCatalog(
                        new DirectoryCatalog("."),
                        new AssemblyCatalog(Assembly.GetExecutingAssembly()),
                        new AssemblyCatalog(Assembly.GetAssembly(typeof(IController)), registrationBuilder));

    BTW, a lot of references use

    registration.Implements<IController>(). Export<IController>();

    however, I do not see where RegistrationBuilder.Implements<>() exists



    • Edited by jfras2009 Monday, August 26, 2013 1:26 PM
    • Marked as answer by Damon Bu - MSFT Friday, August 30, 2013 1:39 AM
    Monday, August 26, 2013 1:25 PM

All replies

  • Hi jfras2009,

    Welcome to the MSDN forum.

    According to your description, you want to add a registrationBuilder to a container.

    Based on my research, you can have a look at the blog link below.

    http://blogs.msdn.com/b/hammett/archive/2011/03/08/mef-s-convention-model.aspx

    To save you some time, I share the sample here. Hope it can help you !

    using System;
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;
    using System.ComponentModel.Composition.Registration;
    class Program
    {
        static void Main(string[] args)
        {
            var registration = new RegistrationBuilder();
            registration.Implements<IController>().
                Export<IController>();
            var catalog = new AssemblyCatalog(
                typeof(Program).Assembly, registration);
            var container = new CompositionContainer(catalog);
        }
    }


    If you have any question, just feel free to let me know.

    Have a nice day!
    Damon


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Sunday, August 25, 2013 3:10 AM
  • I fixed my problem.  The type I needed was in a different assembly.

                var catalog = new AggregateCatalog(
                        new DirectoryCatalog("."),
                        new AssemblyCatalog(Assembly.GetExecutingAssembly()),
                        new AssemblyCatalog(Assembly.GetAssembly(typeof(IController)), registrationBuilder));

    BTW, a lot of references use

    registration.Implements<IController>(). Export<IController>();

    however, I do not see where RegistrationBuilder.Implements<>() exists



    • Edited by jfras2009 Monday, August 26, 2013 1:26 PM
    • Marked as answer by Damon Bu - MSFT Friday, August 30, 2013 1:39 AM
    Monday, August 26, 2013 1:25 PM