public void GetValuesTest() { var container = ContainerFactory.Create(); ITest t = new T1(); string name = AttributedModelServices.GetContractName(typeof(ITest)); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(name, t); container.Compose(batch); IEnumerable <ITest> values = container.GetExportedValues <ITest>(); Assert.AreEqual(t, values.First(), "TryGetExportedValues should return t (by type)"); values = container.GetExportedValues <ITest>(name); Assert.AreEqual(t, values.First(), "TryGetExportedValues should return t (by name)"); }
public void ReadOnlyPropertyImport_ShouldThrowComposition() { var importer = PartFactory.CreateAttributed(new ReadOnlyPropertyImport()); var container = ContainerFactory.Create(); CompositionBatch batch = new CompositionBatch(); batch.AddPart(importer); batch.AddExportedValue("readonly", "new value"); CompositionAssert.ThrowsError(ErrorId.ImportEngine_PartCannotActivate, ErrorId.ReflectionModel_ImportNotWritable, RetryMode.DoNotRetry, () => { container.Compose(batch); }); }
protected override void Configure() { var catalog = MefHelper.SafeDirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory); AssemblySource.Instance.Select(x => new AssemblyCatalog(x)) .OfType <ComposablePartCatalog>() .ToList().ForEach((c) => { catalog.Catalogs.Add(c); }); GlobalData.MefContainer = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);//// container = CompositionHost.Initialize(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); //batch.AddExportedValue<IWindowManager>(new ScreenLifetimeManagerViewModel()); //batch.AddExportedValue<IEventAggregator>(new WebBoxViewModel()); batch.AddExportedValue(GlobalData.MefContainer); ////batch.AddExportedValue(container); ////batch.AddExportedValue(catalog); //this.Container.ComposeParts(this); GlobalData.MefContainer.Compose(batch);//// container.Compose(batch); //EFLogger.EFLogger.Init(); Coroutine.Completed += (s, e) => { if (e.Error != null) { MessageBox.Show(e.Error.Message); } }; }
public void BatchAddRemove_ShouldFireEvents() { var container = ContainerFactory.Create(); var batch = new CompositionBatch(); var exportPart = batch.AddExportedValue <object>("MyExport", new object()); container.Compose(batch); var eventListener = new ExportProviderListener(container, container); batch = new CompositionBatch(); batch.RemovePart(exportPart); batch.AddExportedValue <object>("MyExport2", new object()); eventListener.VerifyCompose(batch); }
public void ImportValueMismatchFromInt32ToDateTime() { var container = ContainerFactory.Create(); CompositionBatch batch = new CompositionBatch(); batch.AddPart(new ImportValueTypes()); batch.AddExportedValue("DateTime", typeof(DateTime), 42); CompositionAssert.ThrowsError(ErrorId.ImportEngine_PartCannotSetImport, ErrorId.ReflectionModel_ImportNotAssignableFromExport, RetryMode.DoNotRetry, () => { container.Compose(batch); }); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #if !(DEBUG) DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; #endif InitializeCultures(); if (Environment.OSVersion.Version < new Version(6, 3)) { MessageBox.Show(Presentation.Properties.Resources.NewerWindowsRequired, ApplicationInfo.ProductName, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(1); } catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(WafConfiguration).Assembly)); // Add the Waf.MusicManager.Applications assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly)); // Add this assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly)); container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); // Initialize all presentation services var presentationServices = container.GetExportedValues <IPresentationService>(); foreach (var presentationService in presentationServices) { presentationService.Initialize(); } // Initialize and run all module controllers moduleControllers = container.GetExportedValues <IModuleController>(); foreach (var moduleController in moduleControllers) { moduleController.Initialize(); } foreach (var moduleController in moduleControllers) { moduleController.Run(); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); ObjectBase.Container = MEFLoader.Init(new List <ComposablePartCatalog>() { new AssemblyCatalog(Assembly.GetExecutingAssembly()) }); eventAggregator = new EventAggregator(); var compositionBatch = new CompositionBatch(); compositionBatch.AddExportedValue(this.eventAggregator); ObjectBase.Container.Compose(compositionBatch); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); InitializeCultures(); ServicePointManager.DefaultConnectionLimit = 400; // Trust all SSL hosts since tumblr.com messed up their ssl cert on amazon s3. ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate); catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(WafConfiguration).Assembly)); // Add the TumblThree.Applications assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly)); // Add the TumblThree.Domain assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(IBlog).Assembly)); // Add the TumblThree.Presentation assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly)); container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); // Initialize all presentation services IEnumerable <IPresentationService> presentationServices = container.GetExportedValues <IPresentationService>(); foreach (IPresentationService presentationService in presentationServices) { presentationService.Initialize(); } // Initialize and run all module controllers moduleControllers = container.GetExportedValues <IModuleController>(); foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); } foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); } QueueOnDispatcher.Initialize(); }
private CompositionContainer GetCompositionContainer() { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); catalog.Catalogs.Add(new AssemblyCatalog(typeof(AppsTracker.Data.Repository.IRepository).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(AppsTracker.Common.Communication.Mediator).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(AppsTracker.Tracking.ITrackingModule).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(AppsTracker.Views.MainWindow).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(AppsTracker.Domain.IUseCase <>).Assembly)); var container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); return(container); }
public MockTestClassBase() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new TypeCatalog( typeof(CompareService) )); MockContainer = new CompositionContainer(catalog); MockContainer.ComposeExportedValue(mockCompareConfigDocumentType.Object); MockContainer.ComposeExportedValue(mockReadFileService.Object); MockContainer.ComposeExportedValue(mockAnalyzeService.Object); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(MockContainer); MockContainer.Compose(batch); }
private static CompositionContainer CreateParentChildContainerWithNonSharedImporter() { var parentCat = CatalogFactory.CreateAttributed(typeof(AnyPartDisposable), typeof(AnyPartDisposableRecomposable), typeof(AnyPartRecomposable), typeof(AnyPartSimple)); var parent = new CompositionContainer(parentCat); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue("Value", 21); parent.Compose(batch); var childCat = CatalogFactory.CreateAttributed(typeof(NonSharedImporter)); var child = new CompositionContainer(childCat, parent); return(child); }
protected override void OnTestInitialize() { base.OnTestInitialize(); AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(MockMessageService).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(ApplicationsTest).Assembly)); OnCatalogInitialize(catalog); container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); }
public void ImportIntoDerivationOfExportsException() { var container = ContainerFactory.Create(); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue("derived", typeof(DerivedExport), 42); var d = new DerivedExportsImporter(); batch.AddPart(d); CompositionAssert.ThrowsError(ErrorId.ImportEngine_PartCannotSetImport, ErrorId.ReflectionModel_ImportNotAssignableFromExport, RetryMode.DoNotRetry, () => { container.Compose(batch); }); }
public void AddService(Type t, object owner, object instance) { string contract = AttributedModelServices.GetContractName(t); Debug.Assert(!string.IsNullOrEmpty(contract), "Every type must have a contract name"); // we want to remove stale instances of a service, if they exist, regardless of who put them there RemoveService(t, null); var batch = new CompositionBatch(); var part = batch.AddExportedValue(contract, instance); Debug.Assert(part != null, "Adding an exported value must return a non-null part"); tempParts.Add(contract, new OwnedComposablePart { Owner = owner, Part = part }); TempContainer.Compose(batch); }
public void AddService(Type t, object instance) { if (!Initialized) { log.Error("ExportProvider is not initialized, cannot add service."); return; } var batch = new CompositionBatch(); string contract = AttributedModelServices.GetContractName(t); Debug.Assert(!string.IsNullOrEmpty(contract), "Every type must have a contract name"); var part = batch.AddExportedValue(contract, instance); Debug.Assert(part != null, "Adding an exported value must return a non-null part"); tempParts.Add(contract, part); tempContainer.Compose(batch); }
public void Initialize() { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(MockMessageService).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestClassBase).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleController).Assembly)); OnCatalogInitialize(catalog); Container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(Container); Container.Compose(batch); OnInitialize(); }
public void InjectionTest() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new TypeCatalog( typeof(MessageService) )); var container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); var service = container.GetExportedValue <IMessageService>(); Assert.IsNotNull(service); }
private void Compose() { try { var first = new AssemblyCatalog(Assembly.GetExecutingAssembly()); var container = new CompositionContainer(first); var batch = new CompositionBatch(); batch.AddExportedValue <IFileSystem>(new FileSystem()); batch.AddPart(this); container.Compose(batch); } catch (ReflectionTypeLoadException ex) { _logger.Error(@"Unable to load: \r\n{0}", string.Join("\r\n", ex.LoaderExceptions.Select(e => e.Message))); throw; } }
public void AppliedStateStored_ShouldRevertStateOnFailure() { var container = ContainerFactory.CreateWithAttributedCatalog(typeof(AllWorkItems), typeof(WorkItem), typeof(Ids)); var workItems = container.GetExportedValue <AllWorkItems>(); Assert.Equal(1, workItems.WorkItems.Length); var batch = new CompositionBatch(); batch.AddExportedValue("WorkItem.Id", "B"); batch.AddPart(new ClassWithMissingImport()); ExceptionAssert.Throws <ChangeRejectedException>(() => container.Compose(batch)); Assert.Equal("MyId", workItems.WorkItems[0].Value.Id); }
public void ImportCompletedChildNeedsParentContainer() { var cat = CatalogFactory.CreateDefaultAttributed(); var parent = new CompositionContainer(cat); CompositionBatch parentBatch = new CompositionBatch(); CompositionBatch childBatch = new CompositionBatch(); CompositionBatch child2Batch = new CompositionBatch(); parentBatch.AddExportedValue <ICompositionService>(parent); parent.Compose(parentBatch); var child = new CompositionContainer(parent); var child2 = new CompositionContainer(parent); var parentImporter = new MyNotifyImportImporter(parent); var childImporter = new MyNotifyImportImporter(child); var child2Importer = new MyNotifyImportImporter(child2); parentBatch = new CompositionBatch(); parentBatch.AddPart(parentImporter); childBatch.AddPart(childImporter); child2Batch.AddPart(child2Importer); parent.Compose(parentBatch); child.Compose(childBatch); child2.Compose(child2Batch); Assert.AreEqual(1, parentImporter.ImportCompletedCallCount); Assert.AreEqual(1, childImporter.ImportCompletedCallCount); Assert.AreEqual(1, child2Importer.ImportCompletedCallCount); MyNotifyImportExporter parentExporter = parent.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter"); Assert.AreEqual(1, parentExporter.ImportCompletedCallCount); MyNotifyImportExporter childExporter = child.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter"); Assert.AreEqual(1, childExporter.ImportCompletedCallCount); MyNotifyImportExporter child2Exporter = child2.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter"); Assert.AreEqual(1, child2Exporter.ImportCompletedCallCount); }
public void TestInitialize() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(MockMessageService).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestClassBase).Assembly)); catalog.Catalogs.Add(new FilteredCatalog(new AssemblyCatalog(typeof(ModuleController).Assembly), x => ExcludeTypes(x, typeof(IEntityController), typeof(IEntityService)))); OnCatalogInitialize(catalog); container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); OnTestInitialize(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Log.App.Info("{0} {1} is starting; OS: {2}", ApplicationInfo.ProductName, ApplicationInfo.Version, Environment.OSVersion); DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; catalog = new AggregateCatalog(); // Add the WinApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMessageService).Assembly)); // Load module assemblies as well. See App.config file. foreach (string moduleAssembly in Settings.Default.ModuleAssemblies) { catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly)); } container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); // Initialize all presentation services var presentationServices = container.GetExportedValues <IPresentationService>(); foreach (var presentationService in presentationServices) { presentationService.Initialize(); } // Initialize and run all module controllers moduleControllers = container.GetExportedValues <IModuleController>(); foreach (var moduleController in moduleControllers) { moduleController.Initialize(); } foreach (var moduleController in moduleControllers) { moduleController.Run(); } }
public void ImportCollections_WriteOnlyArray() { var container = ContainerFactory.Create(); var batch = new CompositionBatch(); var importer = new ImporterWriteOnlyArray(); List <int> values = new List <int>() { 21, 32, 43 }; batch.AddPart(importer); values.ForEach(v => batch.AddExportedValue("Value", v)); container.Compose(batch); EnumerableAssert.AreEqual(values, importer.PublicArray); }
protected override void Configure() { var priorityAssemblies = SelectAssemblies(); var priorityCatalog = new AggregateCatalog(priorityAssemblies.Select(x => new AssemblyCatalog(x))); var catalog = new CatalogExportProvider(priorityCatalog); _container = new CompositionContainer(catalog); catalog.SourceProvider = _container; var batch = new CompositionBatch(); BindServices(batch); batch.AddExportedValue(catalog); _container.Compose(batch); base.Configure(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(Model).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMessageService).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); controller = container.GetExportedValue <ApplicationController>(); controller.Initialize(); controller.Run(); }
private CompositionBatch CreateBatch(IEnumerable <Tuple <Type, object> > parts) { var batch = new CompositionBatch(); foreach (var item in parts) { var contractName = AttributedModelServices.GetContractName(item.Item1); var typeIdentity = AttributedModelServices.GetTypeIdentity(item.Item1); batch.AddExport(new Export(contractName, new Dictionary <string, object> { { "ExportTypeIdentity", typeIdentity } }, () => item.Item2)); } batch.AddExportedValue <ICompositionService>(container); return(batch); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); InitializeCultures(); System.Net.ServicePointManager.DefaultConnectionLimit = 400; catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(WafConfiguration).Assembly)); // Add the TumblThree.Applications assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly)); // Add this assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly)); container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); // Initialize all presentation services IEnumerable <IPresentationService> presentationServices = container.GetExportedValues <IPresentationService>(); foreach (IPresentationService presentationService in presentationServices) { presentationService.Initialize(); } // Initialize and run all module controllers moduleControllers = container.GetExportedValues <IModuleController>(); foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); } foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); } Applications.QueueOnDispatcher.Initialize(); }
protected override void OnStartup(object sender, StartupEventArgs e) { var hack = new CompositionBatch(); hack.AddExportedValue(Container); MefContainer.Compose(hack); var startupTasksLogger = LogManager.GetLogger("StartupTasks"); try { ExecuteStartupTasks(startupTasksLogger); } catch (Exception ex) { startupTasksLogger.ErrorException("Error executing startup tasks", ex); } base.OnStartup(sender, e); }
public void Initialize() { CultureInfo.CurrentCulture = new CultureInfo("en-US"); CultureInfo.CurrentUICulture = new CultureInfo("en-US"); var catalog = new AggregateCatalog(); OnCatalogInitialize(catalog); Container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(Container); Container.Compose(batch); Get <RichTextDocumentController>(); Get <FileController>(); OnInitialize(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); AggregateCatalog catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly)); // Add the WafApplication assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); controller = container.GetExportedValue <ApplicationController>(); controller.Initialize(); controller.Run(); }