static int Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var catalog = new AttributedAssemblyPartCatalog(System.Reflection.Assembly.GetExecutingAssembly()); var container = new CompositionContainer(catalog); container.Compose(); var inspectors = container.GetExportedObjects<IAudioFileInspector>(); /*List<IAudioFileInspector> inspectors = new List<IAudioFileInspector>(); inspectors.Add(new WaveFileInspector()); inspectors.Add(new MidiFileInspector()); inspectors.Add(new SoundFontInspector()); inspectors.Add(new CakewalkMapInspector());*/ if (args.Length > 0) { if (args[0] == "-install") { try { OptionsForm.Associate(inspectors); Console.WriteLine("Created {0} file associations", inspectors.Count); } catch (Exception e) { Console.WriteLine("Unable to create file associations"); Console.WriteLine(e.ToString()); return -1; } return 0; } else if (args[0] == "-uninstall") { try { OptionsForm.Disassociate(inspectors); Console.WriteLine("Removed {0} file associations", inspectors.Count); } catch (Exception e) { Console.WriteLine("Unable to remove file associations"); Console.WriteLine(e.ToString()); return -1; } return 0; } } var mainForm = container.GetExportedObject<AudioFileInspectorForm>(); mainForm.CommandLineArguments = args; Application.Run(mainForm); return 0; }
private static CompositionContainer CreateContainer() { //Create assembly catalog from this assembly var Catalog = new AssemblyCatalog(System.Reflection.Assembly.GetEntryAssembly()); //Create a CompositionContainer from this assembly var Container = new CompositionContainer(Catalog); //Create a batch var Batch = new CompositionBatch(); //Add the container to the batch Batch.AddExportedValue(Container); Container.Compose(Batch); return(Container); }
static void Main(string[] args) { CompositionContainer container = new CompositionContainer(); CompositionBatch batch = new CompositionBatch(); batch.AddPart(AttributedModelServices.CreatePart(new Part1())); batch.AddPart(AttributedModelServices.CreatePart(new Part2())); batch.AddPart(AttributedModelServices.CreatePart(new Part3())); container.Compose(batch); Part3 _part = container.GetExportedValue <Part3>(); Console.WriteLine(_part.data.data.data); Console.ReadLine(); }
void ConfigureContainer() { container = CompositionHost.Initialize( new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>())); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue <UploadPhotoManagerViewModel>(new UploadPhotoManagerViewModel()); batch.AddExportedValue(container); container.Compose(batch); }
private static MEFHost GetComposedMefHost(ScriptCsCatalog catalog) { // arrange var container = new CompositionContainer(catalog); var batch = new CompositionBatch(); var mefHost = new MEFHost(); batch.AddPart(mefHost); // act container.Compose(batch); return(mefHost); }
public void Import_OptIn_AllowRecomposition() { var container = new CompositionContainer(); var importer = new Class_OptIn_AllowRecompositionImports(); CompositionBatch batch = new CompositionBatch(); batch.AddPart(importer); var valueKey = batch.AddExportedValue("Value", 21); container.Compose(batch); // Initial compose Value should be 21 Assert.Equal(21, importer.Value); // Recompose Value to be 42 batch = new CompositionBatch(); batch.RemovePart(valueKey); batch.AddExportedValue("Value", 42); container.Compose(batch); Assert.Equal(42, importer.Value); }
private static void TryCompose(object importer, TypeCatalog catalog, IEnumerable <Export> exports) { CompositionBatch batch = new CompositionBatch(); batch.AddPart(importer); foreach (Export item in exports) { batch.AddExport(item); } using (CompositionContainer container = new CompositionContainer(catalog)) { container.Compose(batch); } }
protected TestClassBase() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new TypeCatalog( typeof(JsonDocumentService), typeof(FileActionService), typeof(CompareConfigDocumentType), typeof(ReadFileService), typeof(AnalyzeService), typeof(CompareService) )); container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); }
protected override void Configure() { container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>())); CompositionBatch batch = new CompositionBatch(); IEventAggregator eventAggregator = new EventAggregator(); batch.AddExportedValue <IWindowManager>(new WindowManager()); //As you can see from the line below, it's possible to add custom classes to the container, these can then be retrieved by using IoC.Get<ClassName>() anywhere. //batch.AddExportedValue<UserAccount>(m_userAccount); batch.AddExportedValue <IEventAggregator>(eventAggregator); batch.AddExportedValue(container); container.Compose(batch); }
//用MEF组合部件 protected override void Configure() { _container = new CompositionContainer(new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() )); //如果还有自己的部件都加在这个地方 var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(_container); _container.Compose(batch); }
public static void ComposeExportedValue(this CompositionContainer container, Type contractType, object exportedValue) { Contract.Requires <ArgumentNullException>(container != null); Contract.Requires <ArgumentNullException>(contractType != null); Contract.Requires <ArgumentNullException>(exportedValue != null); var contractName = AttributedModelServices.GetTypeIdentity(contractType); var b = new CompositionBatch(); var m = new Dictionary <string, object>(); m[CompositionConstants.ExportTypeIdentityMetadataName] = contractName; b.AddExport(new Export(contractName, m, () => exportedValue)); container.Compose(b); }
protected override void Configure() { container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x))) ); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(container); container.Compose(batch); }
protected virtual void Configure() { var catalogs = AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).Cast <ComposablePartCatalog>().ToList(); var wd = Directory.GetCurrentDirectory(); var aggCatalog = new AggregateCatalog(catalogs); _container = new CompositionContainer(aggCatalog); var batch = new CompositionBatch(); //下面必须EventAggregator实例 batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue <IWindowManager>(new WindowManager()); _container.Compose(batch); }
[ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. public void ImportCompletedChildDoesnotNeedParentContainer() { var cat = CatalogFactory.CreateDefaultAttributed(); var parent = new CompositionContainer(cat); CompositionBatch parentBatch = new CompositionBatch(); CompositionBatch childBatch = new CompositionBatch(); parentBatch.AddExportedValue <ICompositionService>(parent); parent.Compose(parentBatch); var child = new CompositionContainer(parent); var parentImporter = new MyNotifyImportImporter(parent); var childImporter = new MyNotifyImportImporter(child); parentBatch = new CompositionBatch(); parentBatch.AddPart(parentImporter); childBatch.AddParts(childImporter, new MyNotifyImportExporter()); child.Compose(childBatch); Assert.Equal(0, parentImporter.ImportCompletedCallCount); Assert.Equal(1, childImporter.ImportCompletedCallCount); // Parent will become bound at this point. MyNotifyImportExporter parentExporter = parent.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter"); parent.Compose(parentBatch); Assert.Equal(1, parentImporter.ImportCompletedCallCount); Assert.Equal(1, parentExporter.ImportCompletedCallCount); MyNotifyImportExporter childExporter = child.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter"); Assert.Equal(1, childExporter.ImportCompletedCallCount); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Log.App.Info("{0} {1} is starting; OS: {2}", ApplicationInfo.ProductName, ApplicationInfo.Version, Environment.OSVersion); #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); 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 Form1() { InitializeComponent(); setText = new SetTextDelegate(SetText); //would get this from file..... var mainHtml = @"<html> <head></head> <body> <div style='color:red'>This is not an import or export</div> <br/> <!-- both of these will be matched by a single export --> <div import='multipleExport1'></div> <div import='multipleExport2'></div> <br/> <div import='exactlyOneAllowsRecomposition' cardinality='ExactlyOne' isRecomposable='true'></div> <br/> <!-- through the allowed recomposition will demonstrate the cardinality of ZeroOrOne, initially matched with one --> <div import='zeroOrOneAllowRecomposition' cardinality='ZeroOrOne' isRecomposable='true'></div> <br/> <!-- demonstrates that recomposition when not specified will throw - initially matches none --> <div import='zeroOrOneDoNotAllowRecomposition' cardinality='ZeroOrOne'></div> <br/> <!-- both of these will be matched by exports that also have imports, the first is an import export --> <div import='exportAndImportMany'></div> <div import='exportWithChildImports'></div> <br/> <!-- this import will have an import that has already been specified - exportAndImportMany, demonstrating --> <!-- recomposition with an import that has also been recomposed. Initially matches none --> <div import='importsRecomposed' isRecomposable='true' cardinality='ZeroOrOne'></div> </body> "; webBrowser1.DocumentText = mainHtml; Application.DoEvents(); var doc = webBrowser1.Document; var htmlPagePart = HTMLComposablePart.CreateRootPart(doc.Body); DirectoryInfo partsDirectory = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar + compositionDirectoryName); htmlCatalog = new WebBrowserDirectoryCatalog(doc, partsDirectory, SearchOption.AllDirectories, (f) => { return(f.Extension == ".htmlPart"); }); htmlCatalog.RecompositionAttemptEvent += HtmlCatalog_RecompositionAttemptEvent; container = new CompositionContainer(htmlCatalog); CompositionBatch batch = new CompositionBatch(new ComposablePart[] { htmlPagePart }, Enumerable.Empty <ComposablePart>()); container.Compose(batch); }
private static void Initialize() { catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(Parser).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFile(Path.GetFullPath("JsonComparer.Services.dll")))); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFile(Path.GetFullPath("JsonComparer.Reports.dll")))); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFile(Path.GetFullPath("JsonComparer.Reports.Excel.dll")))); container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); }
private ICommandConverter[] SetupCommandConverter() { _container = new CompositionContainer(); var batch = new CompositionBatch(); _item = new SimpleCommand(); batch.AddExportedValue <IItem>(_item); _container.Compose(batch); var converters = new[] { new ICommandConverter(_container) }; _luceneStorage = new LuceneStorage(converters); return(converters); }
protected void RegisterServices() { var catalog = new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ); container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(container); container.Compose(batch); }
public void ImportTest() { var exporter = new TestExportBinder(); var importer = new TestImportBinder(); CompositionContainer container = ContainerFactory.Create(); CompositionBatch batch = new CompositionBatch(); batch.AddPart(importer); batch.AddPart(exporter); container.Compose(batch); ExportsAssert.AreEqual(importer.SetImports["single"], 42); ExportsAssert.AreEqual(importer.SetImports["multi"], 1, 2, 3); }
public MockTestClassBase() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new TypeCatalog( typeof(ExcelReportService) )); MockContainer = new CompositionContainer(catalog); MockContainer.ComposeExportedValue(mockExcelReportDocumentType.Object); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(MockContainer); MockContainer.Compose(batch); }
/// <summary> /// use managed extensibility framework to discover effects and load them into the main form /// </summary> private void Compose() { var catalog = new AggregatingComposablePartCatalog(); var mainAssemblyCatalog = new AttributedAssemblyPartCatalog(this.GetType().Assembly); var jsNetCatalog = new AttributedAssemblyPartCatalog(typeof(Effect).Assembly); //var addInEffects = new DirectoryPartCatalog("Effects"); catalog.Catalogs.Add(mainAssemblyCatalog); catalog.Catalogs.Add(jsNetCatalog); //catalog.Catalogs.Add(addInEffects); var container = new CompositionContainer(catalog); container.AddPart(this); container.Compose(); }
/// <summary> /// Initializes a new instance of the <see cref="DiscoverPluginsInAssemblyDirectory"/> class. /// </summary> public DiscoverPluginsInAssemblyDirectory( ) { var disk = new Disk( ); string thisDirectory = disk.DirectoryOfExecutingAssembly ; var catalog = new DirectoryCatalog(thisDirectory); var container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddPart(this); container.Compose(batch); }
private MefHostCompositionService() { Assembly serviceAssembly = Assembly.GetExecutingAssembly(); AggregateCatalog compositionCatalog = new AggregateCatalog(); compositionCatalog.Catalogs.Add(new AssemblyCatalog(serviceAssembly)); compositionCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PkgIds).Assembly)); Container = new CompositionContainer(compositionCatalog); _compositionBatch = new CompositionBatch(); // Compose MEF. Container.Compose(_compositionBatch); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); return; AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); }
//private StatefulHttpClient _httpClient; protected override void Configure() { _container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)))); var batch = new CompositionBatch(); //var statefulHttpClient = new StatefulHttpClient(new HttpClient(), new CookieContainer()); var messageAggregator = new MessageAggregator(); _msg = messageAggregator; //_httpClient = statefulHttpClient; //batch.AddExportedValue<INavigator>(statefulHttpClient); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IMessageAggregator>(messageAggregator); batch.AddExportedValue(_container); _container.Compose(batch); }
public static void ComposeBatch(this CompositionContainer container, params object[] parts) { try { var batch = new CompositionBatch(); foreach (var o in parts) { batch.AddPart(o); } container.Compose(batch); } catch (ArgumentNullException) { } }
public void AnyPart_DisposableRecomposabeImport_ShouldNotBeCollected() { var catalog = new TypeCatalog(typeof(AnyPartDisposableRecomposable)); var container = new CompositionContainer(catalog); // Setup dependency CompositionBatch batch = new CompositionBatch(); var valueKey = batch.AddExportedValue("Value", 21); container.Compose(batch); batch = null; var refTracker = new ReferenceTracker(); refTracker.AddReferencesNotExpectedToBeCollected( container.GetExportedValue <AnyPartDisposableRecomposable>()); refTracker.CollectAndAssert(); // Lets make sure recomposition doesn't blow anything up here. batch = new CompositionBatch(); batch.RemovePart(valueKey); batch.AddExportedValue("Value", 42); container.Compose(batch); batch = null; var exportedValue = (AnyPartDisposableRecomposable)refTracker.ReferencesNotExpectedToBeCollected[0].Target; Assert.AreEqual(42, exportedValue.Value); GC.KeepAlive(container); container.Dispose(); Assert.IsTrue(exportedValue.IsDisposed, "Any parts should be disposed with the container!"); }
public void AddService(Type t, object owner, object instance) { if (!Initialized) { log.Error("ExportProvider is not initialized, cannot add service."); return; } 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 ImportCollectionsFormContainerAndCatalog() { var cat = CatalogFactory.CreateDefaultAttributed(); var container = new CompositionContainer(cat); Importer importer = new Importer(); CompositionBatch batch = new CompositionBatch(); batch.AddParts(importer , new ExporterDefault21(22) , new ExporterDefault42(43)); container.Compose(batch); importer.VerifyImport(22, 43, 21, 42); }
protected override void Configure() { var assemblyCatalogs = m_Assemblies.Select(x => new AssemblyCatalog(x)); var catalog = new AggregateCatalog(assemblyCatalogs); m_Container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <Func <IMessageBox> >(() => m_Container.GetExportedValue <IMessageBox>()); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(m_Container); m_Container.Compose(batch); }
public SSBootstraper() { var aggregateCatalog = new AggregateCatalog(); string currentPath = Directory.GetCurrentDirectory(); aggregateCatalog.Catalogs.Add(new DirectoryCatalog(currentPath)); aggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SSBootstraper).Assembly)); _container = new CompositionContainer(aggregateCatalog); var logger = new SSLogger(); var composition = new CompositionBatch(); composition.AddExportedValue(_container); composition.AddExportedValue(logger); _container.Compose(composition); _mainViewModel = _container.GetExportedValue <ISSMainViewModel>(); }
public HelloProgram() { this.Services = new List<IHelloService>(); if (!Directory.Exists("PlugIns")) { Directory.CreateDirectory("PlugIns"); } AggregatingComposablePartCatalog catalog = new AggregatingComposablePartCatalog(); catalog.Catalogs.Add(new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly())); catalog.Catalogs.Add(new DirectoryPartCatalog("PlugIns")); CompositionContainer container = new CompositionContainer(catalog.CreateResolver()); container.AddPart(this); container.Compose(); }
//[ImportMany(typeof(IFormExstension), AllowRecomposition = true)] //public List<IFormExstension> FormExtensions { get; set; } public void LoadExtensions() { string path = Application.StartupPath + @"\Extensions"; if(Directory.Exists(path)) { var catalog = new AggregateCatalog( new AssemblyCatalog(Assembly.GetExecutingAssembly()), new DirectoryCatalog(path)); var batch = new CompositionBatch(); batch.AddPart(this); _container = new CompositionContainer(catalog); try { _container.Compose(batch); } catch (CompositionException compositionException) { MessageBox.Show(compositionException.ToString()); } } }