Exemplo n.º 1
0
        private bool Compose()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMefShapesGame).Assembly));
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(DefaultDimensions).Assembly));
            var partCreatorEP = new DynamicInstantiationExportProvider();

            this._container = new CompositionContainer(catalog, partCreatorEP);
            partCreatorEP.SourceProvider = this._container;

            CompositionBatch batch = new CompositionBatch();

            batch.AddPart(this);
            batch.AddExportedValue <ICompositionService>(this._container);
            batch.AddExportedValue <AggregateCatalog>(catalog);

            try
            {
                this._container.Compose(batch);
            }
            catch (CompositionException compositionException)
            {
                MessageBox.Show(compositionException.ToString());
                Shutdown(1);
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var catalog = new AggregateCatalog(new AssemblyCatalog(typeof(Program).Assembly));
            var dynamicInstantiationProvider = new DynamicInstantiationExportProvider();
            var container = new CompositionContainer(catalog, dynamicInstantiationProvider);

            dynamicInstantiationProvider.SourceProvider = container;

            var cafe = container.GetExportedValue <Cafe>();

            cafe.Run();

            Console.WriteLine("*****");

            catalog.Catalogs.Add(new TypeCatalog(typeof(Sumatran)));

            cafe.Run();
        }