private static IUnityContainer ConfigureContainer(IServiceProvider package, ServiceLocatorOptions options) { if (package == null) throw new ArgumentNullException(nameof(package), $"{nameof(package)} is null."); IUnityContainer container = new UnityContainer(); container.AddExtension(new ServiceProviderUnityExtension(package, options)); container.RegisterType<IToolkit, TookitImpl>(new ContainerControlledLifetimeManager()); container.RegisterTypes(new SolutionExplorerNodeFactoryRegistrationConvention()); container.RegisterType<IEnumerable<ISolutionExplorerNodeFactory>, ISolutionExplorerNodeFactory[]>(); container.RegisterType<ISolutionExplorerNodeFactory, GlobalSolutionExplorerNodeFactory>(); container.RegisterType<ISolutionExplorer, SolutionExplorer>(); container.RegisterType<IOutputWindow, OutputWindow>(new ContainerControlledLifetimeManager()); container.RegisterType<IDialogService, DialogService>(new ContainerControlledLifetimeManager()); container.RegisterType<IEnumerable<ICommandImplementation>, ICommandImplementation[]>(); container.RegisterInstance<IServiceProvider>(package); container.RegisterType<ICommandManager, CommandManager>(new ContainerControlledLifetimeManager()); UnityServiceLocator serviceLocator = new UnityServiceLocator(container); container.RegisterInstance<IServiceLocator>(serviceLocator); if (!ServiceLocator.IsLocationProviderSet) ServiceLocator.SetLocatorProvider(() => serviceLocator); return container; }
public ServiceProviderUnityExtension(IServiceProvider serviceProvider, ServiceLocatorOptions options) { if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider), $"{nameof(serviceProvider)} is null."); m_options = options; m_serviceProvider = serviceProvider; }
public static IToolkit Initialize(IServiceProvider package, ServiceLocatorOptions serviceLocatorOptions = ServiceLocatorOptions.PackageServiceProvider, bool buildupPackage = true) { IUnityContainer container = ConfigureContainer(package, serviceLocatorOptions); if (buildupPackage) container.BuildUp(package); return container.Resolve<IToolkit>(); }
public ServiceProviderBuildStrategy(IServiceProvider serviceProvider, ServiceLocatorOptions options) { if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider), $"{nameof(serviceProvider)} is null."); m_serviceProvider = serviceProvider; m_componentModel = serviceProvider.GetService<SComponentModel, IComponentModel>(); m_options = options; }