private static void RegisterVisualStudioComponents(ContainerBuilder builder, ApiPortVSPackage serviceProvider)
        {
            builder.RegisterInstance(serviceProvider)
            .As <IResultToolbar>()
            .As <IServiceProvider>();
            builder.RegisterType <Microsoft.VisualStudio.Shell.ErrorListProvider>()
            .AsSelf();
            builder.RegisterType <ErrorListProvider>()
            .As <IErrorListProvider>()
            .SingleInstance();
            builder.Register(_ => Package.GetGlobalService(typeof(SVsWebProxy)))
            .As <IVsWebProxy>();
            builder.Register(_ => Package.GetGlobalService(typeof(SVsWebBrowsingService)))
            .As <IVsWebBrowsingService>();
            builder.Register(_ => Package.GetGlobalService(typeof(SVsSolutionBuildManager)))
            .As <IVsSolutionBuildManager2>();
            builder.Register(_ => Package.GetGlobalService(typeof(SVsStatusbar)))
            .As <IVsStatusbar>();
            builder.RegisterType <DefaultProjectBuilder>()
            .As <IProjectBuilder>();

            builder.RegisterAdapter <IServiceProvider, DTE>(provider => (DTE)provider.GetService(typeof(DTE)));
            builder.RegisterAdapter <IServiceProvider, IVsOutputWindowPane>(provider =>
            {
                var outputWindow = provider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;

                if (outputWindow.GetPane(ref OutputWindowGuid, out IVsOutputWindowPane 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();
        }
        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 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()));
        }
        private static async Tasks.Task RegisterVisualStudioComponentsAsync(ContainerBuilder builder, ApiPortVSPackage serviceProvider)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            builder.RegisterInstance(serviceProvider)
            .As <IResultToolbar>()
            .As <IServiceProvider>();
            builder.RegisterType <Microsoft.VisualStudio.Shell.ErrorListProvider>()
            .AsSelf();
            builder.RegisterType <ErrorListProvider>()
            .As <IErrorListProvider>()
            .SingleInstance();

            builder.RegisterComInstance <SVsWebProxy, IVsWebProxy>();
            builder.RegisterComInstance <SVsWebBrowsingService, IVsWebBrowsingService>();
            builder.RegisterComInstance <SVsStatusbar, IVsStatusbar>();

            builder.RegisterCom <DTE>(await serviceProvider.GetServiceAsync(typeof(DTE)));

            var componentModel = await serviceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

            builder.RegisterInstance(componentModel.GetService <IProjectBuilder>());
            builder.RegisterInstance(componentModel.GetService <IProjectMapper>());

            var outputWindow = await serviceProvider.GetServiceAsync(typeof(SVsOutputWindow));

            builder.RegisterCom <IVsOutputWindowPane>(BuildPane((IVsOutputWindow)outputWindow));
        }
        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.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();
        }
Beispiel #6
0
        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();
        }