public static async Task <ServiceProvider> CreateAsync(ApiPortVSPackage serviceProvider) { var builder = new ContainerBuilder(); builder.RegisterType <VsBrowserReportViewer>() .As <IReportViewer>() .SingleInstance(); builder.RegisterType <ToolbarListReportViewer>() .As <IReportViewer>() .InstancePerLifetimeScope(); builder.RegisterType <ApiPortVsAnalyzer>() .As <IVsApiPortAnalyzer>() .InstancePerLifetimeScope(); // Service registration builder.RegisterInstance(new ProductInformation("ApiPort_VS")) .AsSelf(); builder.RegisterInstance(new AssemblyRedirectResolver(AssemblyDirectory)) .AsSelf(); builder.RegisterType <VisualStudioProxyProvider>() .As <IProxyProvider>() .SingleInstance(); builder.RegisterType <ApiPortService>() .As <IApiPortService>() .WithParameter(TypedParameter.From(DefaultEndpoint)) .SingleInstance(); builder.RegisterType <ApiPortClient>() .AsSelf() .SingleInstance(); builder.Register(_ => OptionsModel.Load()) .As <OptionsModel>() .OnRelease(m => m.Save()) .SingleInstance(); builder.RegisterType <TargetMapper>() .As <ITargetMapper>() .OnActivated(h => h.Instance.LoadFromConfig()) .InstancePerLifetimeScope(); builder.RegisterType <WindowsFileSystem>() .As <IFileSystem>() .SingleInstance(); // Register output services builder.RegisterType <ReportGenerator>() .As <IReportGenerator>() .SingleInstance(); builder.RegisterType <OutputWindowWriter>() .AsSelf() .As <IOutputWindowWriter>() .As <TextWriter>() .SingleInstance(); builder.RegisterType <StatusBarProgressReporter>() .As <IProgressReporter>() .SingleInstance(); builder.RegisterType <ReportFileWriter>() .As <IFileWriter>() .SingleInstance(); builder.Register(GetOutputViewModel) .As <OutputViewModel>() .SingleInstance(); // Register menu handlers builder.RegisterType <AnalyzeMenu>() .AsSelf() .SingleInstance(); builder.RegisterType <FileListAnalyzer>() .AsSelf() .InstancePerLifetimeScope(); builder.RegisterType <ProjectAnalyzer>() .AsSelf() .InstancePerLifetimeScope(); // Register option pane services builder.RegisterType <OptionsPageControl>() .AsSelf() .InstancePerLifetimeScope(); builder.RegisterType <OptionsViewModel>() .AsSelf() .InstancePerLifetimeScope(); // Metadata manipulation registrations builder.RegisterType <CciDependencyFinder>() .As <IDependencyFinder>() .InstancePerLifetimeScope(); builder.RegisterType <CciSourceLineMapper>() .As <ISourceLineMapper>() .InstancePerLifetimeScope(); // VS type registration // Registers all of the Visual Studio Package components. await RegisterVisualStudioComponentsAsync(builder, serviceProvider); return(new ServiceProvider(builder.Build())); }
public ServiceProvider(ApiPortVSPackage serviceProvider) { var builder = new ContainerBuilder(); // VS type registration builder.RegisterType <ErrorListProvider>() .AsSelf() .SingleInstance(); builder.RegisterInstance(serviceProvider) .As <IResultToolbar>() .As <IServiceProvider>(); builder.Register(_ => Package.GetGlobalService(typeof(SVsWebBrowsingService))) .As <IVsWebBrowsingService>(); builder.RegisterType <VsBrowserReportViewer>() .As <IReportViewer>() .SingleInstance(); builder.RegisterType <ToolbarListReportViewer>() .As <IReportViewer>() .InstancePerLifetimeScope(); builder.Register(x => new AssemblyRedirects(s_appConfigFilePath)) .AsSelf() .SingleInstance() .AutoActivate(); builder.RegisterType <ApiPortVsAnalyzer>() .As <IVsApiPortAnalyzer>() .InstancePerLifetimeScope(); builder.Register(_ => Package.GetGlobalService(typeof(SVsSolutionBuildManager))) .As <IVsSolutionBuildManager2>(); builder.RegisterType <ProjectBuilder>() .AsSelf(); // Service registration builder.RegisterInstance(new ProductInformation("ApiPort_VS")) .AsSelf(); builder.RegisterType <ApiPortService>(). As <IApiPortService>(). WithParameter(TypedParameter.From <string>(DefaultEndpoint)) .SingleInstance(); builder.RegisterType <ApiPortClient>() .AsSelf() .SingleInstance(); builder.Register(_ => OptionsModel.Load()) .As <OptionsModel>() .OnRelease(m => m.Save()) .SingleInstance(); builder.RegisterType <TargetMapper>() .As <ITargetMapper>() .OnActivated(h => h.Instance.LoadFromConfig()) .InstancePerLifetimeScope(); builder.RegisterType <WindowsFileSystem>() .As <IFileSystem>() .SingleInstance(); // Register output services builder.RegisterType <ReportGenerator>() .As <IReportGenerator>() .SingleInstance(); builder.RegisterType <OutputWindowWriter>() .AsSelf() .As <TextWriter>() .SingleInstance(); builder.RegisterType <TextWriterProgressReporter>() .As <IProgressReporter>() .SingleInstance(); builder.RegisterType <ReportFileWriter>() .As <IFileWriter>() .SingleInstance(); builder.RegisterAdapter <IServiceProvider, DTE>(provider => (DTE)provider.GetService(typeof(DTE))); builder.RegisterAdapter <IServiceProvider, IVsOutputWindowPane>(provider => { var outputWindow = provider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; IVsOutputWindowPane windowPane; if (outputWindow.GetPane(ref OutputWindowGuid, out windowPane) == S_OK) { return(windowPane); } if (outputWindow.CreatePane(ref OutputWindowGuid, LocalizedStrings.PortabilityOutputTitle, 1, 0) == S_OK) { if (outputWindow.GetPane(ref OutputWindowGuid, out windowPane) == S_OK) { return(windowPane); } } // If a custom window couldn't be opened, open the general purpose window return(provider.GetService(typeof(SVsGeneralOutputWindowPane)) as IVsOutputWindowPane); }).SingleInstance(); builder.RegisterInstance(AnalysisOutputToolWindowControl.Model) .As <OutputViewModel>() .SingleInstance(); // Register menu handlers builder.RegisterType <AnalyzeMenu>() .AsSelf() .SingleInstance(); builder.RegisterType <FileListAnalyzer>() .AsSelf() .InstancePerLifetimeScope(); builder.RegisterType <ProjectAnalyzer>() .AsSelf() .InstancePerLifetimeScope(); // Register option pane services builder.RegisterType <OptionsPageControl>() .AsSelf() .InstancePerLifetimeScope(); builder.RegisterType <OptionsViewModel>() .AsSelf() .InstancePerLifetimeScope(); // Metadata manipulation registrations builder.RegisterType <CciDependencyFinder>() .As <IDependencyFinder>() .InstancePerLifetimeScope(); builder.RegisterType <CciSourceLineMapper>() .As <ISourceLineMapper>() .InstancePerLifetimeScope(); _container = builder.Build(); }
public ServiceProvider(ApiPortVSPackage serviceProvider) { var builder = new ContainerBuilder(); // VS type registration // Registers all of the Visual Studio Package components. RegisterVisualStudioComponents(builder, serviceProvider); builder.RegisterType <VsBrowserReportViewer>() .As <IReportViewer>() .SingleInstance(); builder.RegisterType <ToolbarListReportViewer>() .As <IReportViewer>() .InstancePerLifetimeScope(); builder.RegisterType <ApiPortVsAnalyzer>() .As <IVsApiPortAnalyzer>() .InstancePerLifetimeScope(); // Service registration builder.RegisterInstance(new ProductInformation("ApiPort_VS")) .AsSelf(); builder.RegisterInstance(new AssemblyRedirectResolver(AssemblyDirectory)) .AsSelf(); builder.RegisterType <VisualStudioProxyProvider>() .As <IProxyProvider>() .SingleInstance(); builder.RegisterType <ApiPortService>() .As <IApiPortService>() .WithParameter(TypedParameter.From(DefaultEndpoint)) .SingleInstance(); builder.RegisterType <ApiPortClient>() .AsSelf() .SingleInstance(); builder.Register(_ => OptionsModel.Load()) .As <OptionsModel>() .OnRelease(m => m.Save()) .SingleInstance(); builder.RegisterType <TargetMapper>() .As <ITargetMapper>() .OnActivated(h => h.Instance.LoadFromConfig()) .InstancePerLifetimeScope(); builder.RegisterType <WindowsFileSystem>() .As <IFileSystem>() .SingleInstance(); // Register output services builder.RegisterType <ReportGenerator>() .As <IReportGenerator>() .SingleInstance(); builder.RegisterType <OutputWindowWriter>() .AsSelf() .As <IOutputWindowWriter>() .As <TextWriter>() .SingleInstance(); builder.RegisterType <TextWriterProgressReporter>() .As <IProgressReporter>() .SingleInstance(); builder.RegisterType <ReportFileWriter>() .As <IFileWriter>() .SingleInstance(); builder.RegisterInstance(AnalysisOutputToolWindowControl.Model) .As <OutputViewModel>() .SingleInstance(); // Register menu handlers builder.RegisterType <AnalyzeMenu>() .AsSelf() .SingleInstance(); builder.RegisterType <FileListAnalyzer>() .AsSelf() .InstancePerLifetimeScope(); builder.RegisterType <ProjectAnalyzer>() .AsSelf() .InstancePerLifetimeScope(); builder.RegisterType <COMProjectMapper>() .As <IProjectMapper>() .SingleInstance(); // Register option pane services builder.RegisterType <OptionsPageControl>() .AsSelf() .InstancePerLifetimeScope(); builder.RegisterType <OptionsViewModel>() .AsSelf() .InstancePerLifetimeScope(); // Metadata manipulation registrations builder.RegisterType <CciDependencyFinder>() .As <IDependencyFinder>() .InstancePerLifetimeScope(); builder.RegisterType <CciSourceLineMapper>() .As <ISourceLineMapper>() .InstancePerLifetimeScope(); var dte = Package.GetGlobalService(typeof(DTE)) as DTE; var version = new Version(dte.Version); if (version.Major == 14) { builder.RegisterModule(new VS2015.ServiceProvider()); } else { builder.RegisterModule(new VS2017.ServiceProvider()); } _container = builder.Build(); }