Exemplo n.º 1
0
        public MainMenuViewModel(CompositionContainer container)
        {
            _topLevelMenuItems = new ObservableCollection<MenuItemViewModel>();
            _styleSelector = new MainMenuItemStyleSelector();
            
            var menuItemImports =  container.GetExports<IMenuItem, IMenuItemMetaData>();
            var globalCommandImports = container.GetExports<IGlobalCommand>();

            var menuBuilder = new MenuBuilder(globalCommandImports);

            foreach (var import in menuItemImports.Where(x => x.Metadata.IsMainMenuItem))
            {
                menuBuilder.AddItem(import.Value, import.Metadata);
            }

            foreach (var rootItem in menuBuilder.Build().Children)
            {
                MenuItemViewModel viewModel;

                if (rootItem is MenuSeparatorModel)
                {
                    viewModel  = new MenuSeparatorViewModel();
                }
                else
                {
                    viewModel = new MenuItemViewModel(null, rootItem.HeaderText, rootItem.Command, rootItem.GestureText, rootItem.Children);
                }

                _topLevelMenuItems.Add(viewModel);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">
        /// The args. 
        /// </param>
        public static void Main(string[] args)
        {
            WriteSignature();

            using (AggregateCatalog aggregateCatalog = new AggregateCatalog())
            {
                RegistrationBuilder registrationBuilder = new RegistrationBuilder();

                registrationBuilder.ForTypesDerivedFrom<ICommand>()
                                   .Export(conf => conf.AsContractName(AttributedModelServices.GetContractName(typeof(ICommand))))
                                   .SetCreationPolicy(CreationPolicy.NonShared);
                
                aggregateCatalog.Catalogs.Add(new ApplicationCatalog(registrationBuilder));

                string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string pluginPath = Path.Combine(appPath, "plugins");
                if (Directory.Exists(pluginPath))
                    aggregateCatalog.Catalogs.Add(new DirectoryCatalog(pluginPath, registrationBuilder));

                using (CompositionContainer container = new CompositionContainer(aggregateCatalog))
                {
                    ICommandProvider[] providers = container.GetExports<ICommandProvider>().Select(l => l.Value).ToArray();
                    Type[] commands = providers.SelectMany(p => p.GetCommands()).ToArray();

                    Func<Type, object> mefActivator =
                        t =>
                        {
                            if (!typeof(ICommand).IsAssignableFrom(t))
                                return DefaultActivator.Instance.CreateInstance(t);

                            ImportDefinition importDefinition = new ImportDefinition(ed => (string)ed.Metadata[CompositionConstants.ExportTypeIdentityMetadataName] == AttributedModelServices.GetTypeIdentity(t),
                                                                                     AttributedModelServices.GetContractName(typeof(ICommand)),
                                                                                     ImportCardinality.ExactlyOne,
                                                                                     false,
                                                                                     true);

                            return container.GetExports(importDefinition).First().Value;
                        };

                    ArgumentParserSettings parserSettings = new ArgumentParserSettings
                                                            {
                                                                TypeActivator = new DelegateActivator(mefActivator)
                                                            };

                    ArgumentParser<ICommand> argumentParser = new ArgumentParser<ICommand>(parserSettings, commands);
                    ICommand command;
                    if (argumentParser.TryParse(args, out command))
                    {
                        command.Invoke(container);
                    }
                }
            }
        }
        public AixmConverter()
        {
            List<Assembly> source = AppDomain.CurrentDomain.GetAssemblies().ToList<Assembly>();
            foreach (var asm in source)
            {
                AssemblyCatalog catalog = new AssemblyCatalog(asm);
                CompositionContainer mefContainer = new CompositionContainer(catalog, true);
                var plugins = mefContainer.GetExports<Func<IAixmConverter, JObject, XElement, IEnumerable<JObject>>, IAixmConverterMetadata>().ToArray();
                _elementReaders.AddRange(plugins);
                _elementWriters.AddRange(mefContainer.GetExports<Action<IAixmConverter,int, JObject, XmlWriter>, IAixmConverterMetadata>().ToArray());

            }
            _elementWriters = _elementWriters.OrderBy(k => k.Metadata.WriteOrder).ToList();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">
        /// The args. 
        /// </param>
        public static void Main(string[] args)
        {
            WriteSignature();

            using (AggregateCatalog aggregateCatalog = new AggregateCatalog())
            {
                aggregateCatalog.Catalogs.Add(new ApplicationCatalog());

                string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string pluginPath = Path.Combine(appPath, "plugins");
                if (Directory.Exists(pluginPath))
                    aggregateCatalog.Catalogs.Add(new DirectoryCatalog(pluginPath));

                using (CompositionContainer container = new CompositionContainer(aggregateCatalog))
                {
                    ICommandProvider[] providers = container.GetExports<ICommandProvider>().Select(l => l.Value).ToArray();
                    var commands = providers.SelectMany(p => p.GetCommands()).ToArray();

                    ArgumentParser<ICommand> argumentParser = new ArgumentParser<ICommand>(commands);
                    ICommand command;
                    if (argumentParser.TryParse(args, out command))
                    {
                        command.Invoke(container);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static void LoadContainer(IUnityContainer container, string path, string pattern)
        {
            var directoryCatalog = new DirectoryCatalog(path, pattern);
            var importDefinition = BuildImportDefinition();

            try
            {
                using (var aggregateCatalog = new AggregateCatalog())
                {
                    aggregateCatalog.Catalogs.Add(directoryCatalog);
                    using (var componsitionContainer = new CompositionContainer(aggregateCatalog))
                    {
                        IEnumerable<Export> exports = componsitionContainer.GetExports(importDefinition);
                        IEnumerable<IModule> modules = exports.Select(export => export.Value as IModule).Where(m => m != null);

                        foreach (IModule module in modules)
                        {
                            module.Initialize(container);
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException typeLoadException)
            {
                var builder = new StringBuilder();

                foreach (Exception loaderException in typeLoadException.LoaderExceptions)
                {
                    builder.AppendFormat("{0}\n", loaderException.Message);
                }

                throw new TypeLoadException(builder.ToString(), typeLoadException);
            }
        }
Exemplo n.º 6
0
        public void GetValuesByType()
        {
            var cat = CatalogFactory.CreateDefaultAttributed();

            var container = new CompositionContainer(cat);

            string itestName = AttributedModelServices.GetContractName(typeof(ITest));

            var e1 = container.GetExportedValues<ITest>();
            var e2 = container.GetExports<ITest, object>(itestName);

            Assert.IsInstanceOfType(e1.First(), typeof(T1), "First should be T1");
            Assert.IsInstanceOfType(e1.Skip(1).First(), typeof(T2), "Second should be T2");

            Assert.IsInstanceOfType(e2.First().Value, typeof(T1), "First should be T1");
            Assert.IsInstanceOfType(e2.Skip(1).First().Value, typeof(T2), "Second should be T2");

            CompositionContainer childContainer = new CompositionContainer(container);
            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(new T1());
            container.Compose(batch);
            var t1 = childContainer.GetExportedValue<ITest>();
            var t2 = childContainer.GetExport<ITest, object>(itestName);

            Assert.IsInstanceOfType(t1, typeof(T1), "First (resolved) should be T1");
            Assert.IsInstanceOfType(t2.Value, typeof(T1), "First (resolved) should be T1");
        }
Exemplo n.º 7
0
		public static void LoadCodecs(string path = null, string search = null) {
			if (path == null)
				path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath);

		    if (search == null)
		        search = "Dicom.Native*.dll";

			var log = LogManager.Default.GetLogger("Dicom.Imaging.Codec");
		    log.Debug("Searching {path}\\{wildcard} for Dicom codecs", path, search);

		    var foundAnyCodecs = false;

		    DirectoryCatalog catalog;
		    try {
		        catalog = new DirectoryCatalog(path, search);
		    }
		    catch (Exception ex) {
		        log.Error("Error encountered creating new DirectCatalog({path}, {search}) - {@exception}", path, search, ex);
		        throw;
		    }

			var container = new CompositionContainer(catalog);
			foreach (var lazy in container.GetExports<IDicomCodec>()) {
			    foundAnyCodecs = true;
				var codec = lazy.Value;
				log.Debug("Codec: {codecName}", codec.TransferSyntax.UID.Name);
				_codecs[codec.TransferSyntax] = codec;
			}

		    if (!foundAnyCodecs) {
		        log.Warn("No Dicom codecs were found after searching {path}\\{wildcard}", path, search);
		    }
		}
 public TreatyHelper()
 {
     var catalog = new AssemblyCatalog(this.GetType().Assembly);
     var container = new CompositionContainer(catalog);
     
     this.treaties = container.GetExports<ITreatyProvider>().ToList();
 }
	public void WhenExportIsFiltered_ThenPartIsAvailableButNotExport()
	{
		var catalog = new TypeCatalog(typeof(Foo));
		var filtered = new FilteringReflectionCatalog(catalog)
		{
			ExportFilter = export => !(export.ExportingMember.MemberType == System.Reflection.MemberTypes.Property),
		};

		var container = new CompositionContainer(filtered);

		var exports = container.GetExports<IFoo>();
		var barExports = container.GetExports<IBar>();

		Assert.True(exports.Any());
		Assert.False(barExports.Any());
	}
Exemplo n.º 10
0
        /// <summary>
        /// Loads all SharpShell servers from an assembly.
        /// </summary>
        /// <param name="path">The path to the assembly.</param>
        /// <returns>A ServerEntry for each SharpShell server in the assembly.</returns>
        public static IEnumerable<ServerEntry> LoadServers(string path)
        {
            //  Storage for the servers.
            var servers = new List<ServerEntry>();

            try
            {
                //  Create an assembly catalog for the assembly and a container from it.
                var catalog = new AssemblyCatalog(Path.GetFullPath(path));
                var container = new CompositionContainer(catalog);

                //  Get all exports of type ISharpShellServer.
                var serverTypes = container.GetExports<ISharpShellServer>();

                //  Go through each servertype (creating the instance from the lazy).
                foreach(var serverType in serverTypes)
                {
                    ISharpShellServer server = null;
                    try
                    {
                        server = serverType.Value;
                    }
                    catch (Exception)
                    {
                        servers.Add(new ServerEntry
                        {
                            ServerName = "Invalid",
                            ServerPath = path,
                            ServerType = ServerType.None,
                            ClassId = new Guid(),
                            Server = null,
                            IsInvalid = true
                        });
                        continue;
                    }

                    //  Yield a server entry for the server type.
                    servers.Add(new ServerEntry
                                          {
                                              ServerName = server.DisplayName, 
                                              ServerPath = path,
                                              ServerType = server.ServerType,
                                              ClassId = server.ServerClsid,
                                              Server = server
                                          });

                }
            }
            catch (Exception)
            {
                //  It's almost certainly not a COM server.
                MessageBox.Show("The file '" + Path.GetFileName(path) + "' is not a SharpShell Server.", "Warning");
            }

            //  Return the servers.
            return servers;
        }
Exemplo n.º 11
0
        public void FilterBasedOnMetadataUsingContainsMetadataTest()
        {
            var catalog = new AssemblyCatalog(typeof(FilteringCatalogTests).Assembly);
            var filteredCatalog = new FilteringCatalog(catalog, new ContainsMetadata("key", "value"));
            var container = new CompositionContainer(filteredCatalog);
            var components = container.GetExports<IMetadataComponent>();

            Assert.That(components, Is.Not.Null);
            Assert.That(components.Count(), Is.EqualTo(1));
        }
Exemplo n.º 12
0
        /// <summary>
        /// The register.
        /// </summary>
        /// <param name="container">
        /// The container.
        /// </param>
        public static void Register(IWindsorContainer container)
        {
            var catalog =
                new CatalogBuilder().ForAssembly(typeof(IComponentRegistrarMarker).Assembly).ForMvcAssembly(
                    Assembly.GetExecutingAssembly()).ForMvcAssembliesInDirectory(HttpRuntime.BinDirectory, "Leatn*.dll")
                    .Build();

            var compositionContainer = new CompositionContainer(catalog);
            compositionContainer.GetExports<IComponentRegistrar>().ForeEach(e => e.Value.Register(container));
        }
Exemplo n.º 13
0
        public static int Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("File Watch Directory must be specifed");
                Console.WriteLine("usage: engine.exe path");
                return -1;
            }

            try
            {
                // Example of convention-based approach
                var registration = new RegistrationBuilder();
                registration.ForType<Logger>().Export<ILogger>();
                var assemblyCatalog = new AssemblyCatalog(typeof(Logger).Assembly, registration);

                var catalog = new AggregateCatalog(
                    assemblyCatalog,
                    new DirectoryCatalog(@".\addins"));

                using (var container = new CompositionContainer(catalog))
                {
                    var engine = new ProcessorEngine(new DirectoryInfo(args[0]));

                    // Bind exports to imports
                    container.ComposeParts(engine);

                    var exports = container.GetExports<IFileProcessor, IFileProcessorMetadata>().ToList();

                    Console.WriteLine("{0} File Processor(s) available", exports.Count);

                    if (exports.Count > 0)
                    {
                        foreach (var export in exports)
                        {
                            Console.WriteLine("{0} file type supported", export.Metadata.SupportedExtension);
                        }
                        engine.ProcessFiles();
                    }
                    else
                    {
                        Console.WriteLine("Add File Processors to the Add-in directory");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.ReadLine();
                return -1;
            }
            Console.ReadLine();
            return 0;
        }
Exemplo n.º 14
0
        public void Parts_are_filtered_based_on_shared_lifetime_using_HasCreationPolicy_filter()
        {
            var catalog = new AssemblyCatalog(typeof(FilteringCatalogTests).Assembly);
            var filteredCatalog = new FilteringCatalog(catalog, new HasCreationPolicy(CreationPolicy.Shared));
            var container = new CompositionContainer(filteredCatalog);
            var components = container.GetExports<ILifetimeComponent>();

            Assert.That(components, Is.Not.Null);
            Assert.That(components.Count(), Is.EqualTo(1));
            Assert.That(components.First().Value.GetType(), Is.EqualTo(typeof(LifetimeComponent2)));
        }
Exemplo n.º 15
0
        public void FilterBasedOnNonSharedLifetimeUsingHasCreationPolicyTest()
        {
            var catalog = new AssemblyCatalog(typeof(FilteringCatalogTests).Assembly);
            var filteredCatalog = new FilteringCatalog(catalog, new HasCreationPolicy(CreationPolicy.NonShared));
            var container = new CompositionContainer(filteredCatalog);
            var components = container.GetExports<ILifetimeComponent>();

            Assert.That(components, Is.Not.Null);
            Assert.That(components.Count(), Is.EqualTo(1));
            Assert.That(components.First().Value.GetType(), Is.EqualTo(typeof(LifetimeComponent3)));
        }
Exemplo n.º 16
0
        public void FilterBasedOnAnyLifetimeUsingHasCreationPolicyTest()
        {
            var catalog = new AssemblyCatalog(typeof(FilteringCatalogTests).Assembly);
            var filteredCatalog = new FilteringCatalog(catalog, new HasCreationPolicy(CreationPolicy.Any));
            var container = new CompositionContainer(filteredCatalog);
            var components = container.GetExports<ILifetimeComponent>();

            Assert.That(components, Is.Not.Null);
            Assert.That(components.Count(), Is.EqualTo(2));
            Assert.That(components.Select(t => t.Value).OfType<LifetimeComponent1>().First().GetType(), Is.EqualTo(typeof(LifetimeComponent1)));
            Assert.That(components.Select(t => t.Value).OfType<LifetimeComponent4>().First().GetType(), Is.EqualTo(typeof(LifetimeComponent4)));
        }
Exemplo n.º 17
0
        public void FilterBasedOnMetadataUsingLambdaExpressionTest()
        {
            var catalog = new AssemblyCatalog(typeof(FilteringCatalogTests).Assembly);
            var filteredCatalog = new FilteringCatalog(catalog,
                                                      partDefinition => partDefinition.Metadata.ContainsKey("key") &&
                                                                        partDefinition.Metadata["key"].Equals("value"));
            var container = new CompositionContainer(filteredCatalog);
            var components = container.GetExports<IMetadataComponent>();

            Assert.That(components, Is.Not.Null);
            Assert.That(components.Count(), Is.EqualTo(1));
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.White;
            AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
            ComposablePartCatalog catalog = CatalogServices.GetCatalog();
            
            var container = new CompositionContainer(catalog);
            var pluginExports = container.GetExports<IPlugin, IPluginMetadata>();

            ShowPluginMetadata(pluginExports);
            CreatePluginInstances(pluginExports);
            Console.Read();
        }
Exemplo n.º 19
0
        public static void Initialise()
        {
            var catalog = new CatalogBuilder()
                              .ForAssembly(typeof(IComponentRegistrarMarker).Assembly)
                              .ForMvcAssembly(Assembly.GetExecutingAssembly())
                              .ForMvcAssembliesInDirectory(HttpRuntime.BinDirectory, "Leatn*.dll") // Won't work in Partial trust
                              .Build();

            var compositionContainer = new CompositionContainer(catalog);

            compositionContainer.GetExports<IComponentInitialiser>()
                .ForeEach(e => e.Value.Initialise());
        }
Exemplo n.º 20
0
        private void OnApplicationLoaded(ApplicationLoadedMessage msg)
        {
            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            _container = new CompositionContainer(catalog);
            _container.ComposeParts(this);

            var moduleContainers = _container.GetExports<IModuleContainer>();

            foreach (var module in moduleContainers.SelectMany(mc => mc.Value.GetModules()))
            {
                _bus.SendMessage(new ModuleLoadedMessage(module));
            }
        }
Exemplo n.º 21
0
 public StatSet(Character character)
 {
     stats = new Dictionary<string, IStat>();
     using(var container = new CompositionContainer(new AssemblyCatalog(typeof(StatSet).Assembly)))
     {
         foreach(var val in container.GetExports<Retriever>())
         {
             var method = val.Value;
             var name = method.Method.Name;
             var stat = new DynamicStat(method, character);
             stats[name] = stat;
         }
     }
 }
        /// <summary>
        /// Runs the task.
        /// </summary>
        /// <param name="container"></param>
        public void Run(CompositionContainer container)
        {
            Throw.IfArgumentNull(container, "container");

            var registrars = container
                .GetExports<IRouteRegistrar, IOrderedMetadata>()
                .OrderBy(r => r.Metadata.Order)
                .Select(r => r.Value);

            var routes = RouteTable.Routes;

            foreach (var registrar in registrars)
                registrar.RegisterRoutes(routes);
        }
Exemplo n.º 23
0
		public static Assembly DiscoverMigrationAssembly() {
				var catalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory);
			var container = new CompositionContainer(catalog);
			var migrations = container.GetExports<IMigration, IMigrationCapabilities>();
			var assembliesWithMigrations = (from m in migrations
			                                select m.Value.GetType().Assembly).Distinct();

			if (assembliesWithMigrations.Count() > 1) {
				throw new ApplicationException("Multiple assembly migrations are not supported.");
			} else if(assembliesWithMigrations.Count() == 0) {
				throw new ApplicationException("No migration assemblies were found");
			} else {
				return assembliesWithMigrations.First();
			}
		}
Exemplo n.º 24
0
 public void ImportAll(out IReadOnlyCollection<ImportedMigration> migrations, out IReadOnlyCollection<ImportedAggregateMigration> aggregateMigrations)
 {
     Log.Info("Importing migrations...");
     DateTime start = DateTime.Now;
     var container = new CompositionContainer(_catalog);
     IEnumerable<Lazy<IMigration, IMigrationExportMetadata>> migrationExports = container.GetExports<IMigration, IMigrationExportMetadata>();
     IEnumerable<Lazy<IMigration, IAggregateMigrationExportMetadata>> aggregateMigrationExports = container.GetExports<IMigration, IAggregateMigrationExportMetadata>(AggregateMigrationExportAttribute.ContractName);
     migrations = migrationExports
         .Select(l =>
         {
             var timestamp = ExtractTimestamp(l.Metadata.ModuleName, l.Value);
             var migrationMetadata = new MigrationMetadata(timestamp, l.Metadata.ModuleName, l.Metadata.Tag);
             return new ImportedMigration(l.Value, migrationMetadata, l.Metadata.UseModuleNameAsDefaultSchema);
         }).ToList();
     aggregateMigrations = aggregateMigrationExports
         .Select(l =>
         {
             var timestamp = ExtractTimestamp(l.Metadata.ModuleName, l.Value);
             var aggregateMigrationMetadata = new AggregateMigrationMetadata(timestamp, l.Metadata.ModuleName);
             return new ImportedAggregateMigration(l.Value, aggregateMigrationMetadata);
         }).ToList();
     Log.Verbose(LogCategory.Performance, "Importing migrations took {0}s", (DateTime.Now - start).TotalSeconds);
     Log.Info("Found {0} migration(s) and {1} aggregate migration(s)", migrations.Count, aggregateMigrations.Count);
 }
Exemplo n.º 25
0
        public Parser()
        {
            if (_container == null)
            {
                var catalog = new AggregateCatalog();

                catalog.Catalogs.Add(new AssemblyCatalog(typeof(Parser).Assembly));

                _container = new CompositionContainer(catalog);

                _container.ComposeParts(this);

                tags = _container.GetExports<IBBCode, IBBCodeData>();
            }
        }
	public void WhenPartIsFiltered_ThenItsExportCannotBeRetrieved()
	{
		var catalog = new TypeCatalog(typeof(Foo));
		var filtered = new FilteringReflectionCatalog(catalog)
		{
			//PartFilter = part => part.PartType != typeof(Foo),
			PartFilter = part => part.PartDefinition.Metadata.ContainsKey("IsPublic"),
		};

		var container = new CompositionContainer(filtered);

		var exports = container.GetExports<IFoo>();

		Assert.False(exports.Any());
	}
Exemplo n.º 27
0
		public static void LoadCodecs(string path = null, string search = null) {
			if (path == null)
				path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

			var log = LogManager.GetLogger("Dicom.Imaging.Codec");

			var catalog = (search == null) ?
				new DirectoryCatalog(path) :
				new DirectoryCatalog(path, search);
			var container = new CompositionContainer(catalog);
			foreach (var lazy in container.GetExports<IDicomCodec>()) {
				var codec = lazy.Value;
				log.Debug("Codec: {0}", codec.TransferSyntax.UID.Name);
				_codecs[codec.TransferSyntax] = codec;
			}
		}
Exemplo n.º 28
0
        public IProjectRule[] LoadRules()
        {
            Console.Out.WriteLine("INFO: Scanning for rules...");

            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog("."));
            var container = new CompositionContainer(catalog);
            var rules = container.GetExports<IProjectRule>().Select(x => x.Value).ToArray();
            foreach (var rule in rules)
            {
                Console.Out.WriteLine("INFO: Rule {0} found.", rule.Id);
            }

            Console.Out.WriteLine("INFO: Scanning for rules finished! Rules found: {0}", rules.Count());
            return rules.ToArray();
        }
Exemplo n.º 29
0
 public static void LoadContainer(
     ApplicationParameters parameters, IUnityContainer container, string path, string pattern)
 {
     var importDef = BuildImportDefinition();
     using (var dirCat = new DirectoryCatalog(path, pattern))
     using (var aggregateCatalog = new AggregateCatalog())
     {
         aggregateCatalog.Catalogs.Add(dirCat);
         using (var componsitionContainer = new CompositionContainer(aggregateCatalog))
         {
             var modules = componsitionContainer.GetExports(importDef).Select(e => e.Value).OfType<IModule>();
             var registrar = new ModuleRegistrar(container);
             foreach (var module in modules)
             {
                 module.Initialize(parameters, registrar);
             }
         }
     }
 }
Exemplo n.º 30
0
        public void PartAddedTwice_AppearsTwice()
        {
            //  You probably shouldn't be adding a part to the container twice, but it's not something we're going to check for and throw an exception on
            var container = new CompositionContainer();
            var disposable = new AnyPartDisposable();
            var part = AttributedModelServices.CreatePart(disposable);
            var batch = new CompositionBatch();
            batch.AddPart(part);
            container.Compose(batch);

            batch = new CompositionBatch();
            batch.AddPart(part);
            container.Compose(batch);

            var exports = container.GetExports<AnyPartDisposable>();
            Assert.AreEqual(2, exports.Count());

            container.Dispose();
        }