public void Dispose() { IDisposable i = _instance as IDisposable; if (i != null) { i.Dispose(); } if (type != null && serviceProvider.GetService(type) != null) { serviceProvider.RemoveService(type); } }
/// <summary> /// Retrieves the <see cref="IServiceLocator"/> for the given project. /// </summary> /// <exception cref="ArgumentNullException">The <paramref name="project"/> parameter was null.</exception> /// <exception cref="InvalidOperationException">The required <see cref="IComponentModel"/> service was not found.</exception> public static IServiceLocator GetServiceLocator(this Project project) { Guard.NotNull(nameof(project), project); var components = new OleServiceProvider(project.DTE).GetService <SComponentModel, IComponentModel>(); try { return(components.GetService <IServiceLocatorProvider> ().GetServiceLocator(project)); } catch (ImportCardinalityMismatchException ex) { throw new MissingDependencyException(Strings.ServiceLocator.MissingDependency(typeof(IServiceLocatorProvider)), ex); } }