public static void InitializeServices(Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleProvider) { if (oleProvider == null) { throw new ArgumentNullException("oleProvider"); } if (!servicesInitialized) { try { serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(oleProvider); container = new System.ComponentModel.Design.ServiceContainer(serviceProvider); componentHost = new VsShellComponentModelHost(oleProvider); catalogProvider = new VsCatalogProvider(componentHost); globalCatalog = catalogProvider.GetCatalog("Microsoft.VisualStudio.Default"); if (globalCatalog == null) { throw new InvalidOperationException("T4 Composition services initialization error: Failed to get default composition catalog."); } composition = VsCompositionContainer.Create(globalCatalog); composition.ComposeExportedValue <SVsServiceProvider>(new VsServiceProviderWrapper(container)); localComponentModel = new LocalComponentModel(catalogProvider, composition); container.AddService(typeof(SComponentModel), localComponentModel); container.AddService(typeof(IComponentModel), localComponentModel); AppDomain.CurrentDomain.ProcessExit += new EventHandler(Microsoft.VisualStudio.TextTemplating.VSHost.CompositionServices.CurrentDomain_Cleanup); AppDomain.CurrentDomain.DomainUnload += new EventHandler(Microsoft.VisualStudio.TextTemplating.VSHost.CompositionServices.CurrentDomain_Cleanup); servicesInitialized = true; } catch (Exception) { CleanupFields(); throw; } } }
static ClientPipeLineEventNotifier() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(ClientPipeLineEventNotifier).Assembly)); CompositionContainer container = new CompositionContainer(catalog); VsCompositionContainer.Create(container); clientEventHandlers = VsExportProviderService.GetExportedValues <IClientEventHandler>(); }
static PipeLineEventNotifier() { VsExportProviderService.TryGetExportedValue(out multiTenantService); AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(PipeLineEventNotifier).Assembly)); CompositionContainer container = new CompositionContainer(catalog); VsCompositionContainer.Create(container); serverEventHandlers = VsExportProviderService.GetExportedValues <IServerEventHandler>(); }
public void InitializeContext() { this.testClass = new ValidationTest(); // Exports test class to MEF VsCompositionContainer.Create(new TypeCatalog(typeof(ValidationTest)), new VsExportProviderSettings( VsExportProvidingPreference.BeforeExportsFromOtherContainers)); this.solution = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>(); this.solution.CreateInstance(this.DeploymentDirectory, "Blank"); this.patternManager = VsIdeTestHostContext.ServiceProvider.GetService <IPatternManager>(); var toolkit = this.patternManager.InstalledToolkits.Single(f => f.Id == "NuPattern.Runtime.IntegrationTests.TestToolkit"); UIThreadInvoker.Invoke(new Action(() => this.product = this.patternManager.CreateProduct(toolkit, "Foo"))); }