private bool TryAllInstancesFromServiceLocators <T>(out ICollection <T> instance) where T : class { IEnumerable <T> result; if (UserServiceLocator != null) { result = UserServiceLocator.GetAllInstances <T>(); if (result != null) { instance = result as IList <T>; return(true); } } if (ProviderServiceLocator != null) { result = ProviderServiceLocator.GetAllInstances <T>(); if (result != null) { instance = result as IList <T>; return(true); } } instance = null; return(false); }
private bool TrySingleInstanceFromServiceLocators <T>(out T instance) where T : class { if (UserServiceLocator != null) { instance = UserServiceLocator.GetInstance <T>(); if (instance != null) { return(true); } } if (ProviderServiceLocator != null) { instance = ProviderServiceLocator.GetInstance <T>(); if (instance != null) { return(true); } } instance = null; return(false); }
/// <summary> /// Instantiates an instance of <see cref="ResourceEndpointConfiguration"/>. /// </summary> /// <returns>A <see cref="ResourceEndpointConfiguration"/> instance resolved by one of the <see cref="IServiceLocator"/>s.</returns> /// <exception cref="GlimpseException">An exception is thrown is an instance of <see cref="ResourceEndpointConfiguration"/> is not provided by a <see cref="IServiceLocator"/>.</exception> public ResourceEndpointConfiguration InstantiateResourceEndpointConfiguration() { ResourceEndpointConfiguration result; if (TrySingleInstanceFromServiceLocators(out result)) { return(result); } throw new GlimpseException( string.Format( Resources.InstantiateResourceEndpointConfigurationException, UserServiceLocator == null ? "UserServiceLocator not configured" : UserServiceLocator.GetType().AssemblyQualifiedName, ProviderServiceLocator == null ? "ProviderServiceLocator not configured" : ProviderServiceLocator.GetType().AssemblyQualifiedName)); }
/// <summary> /// Instantiates an instance of <see cref="IFrameworkProvider"/>. /// </summary> /// <returns>A <see cref="IFrameworkProvider"/> instance resolved by one of the <see cref="IServiceLocator"/>s.</returns> /// <exception cref="GlimpseException">An exception is thrown is an instance of <see cref="IFrameworkProvider"/> is not provided by a <see cref="IServiceLocator"/>.</exception> public IFrameworkProvider InstantiateFrameworkProvider() { if (FrameworkProvider != null) { return(FrameworkProvider); } IFrameworkProvider result; if (TrySingleInstanceFromServiceLocators(out result)) { FrameworkProvider = result; return(FrameworkProvider); } throw new GlimpseException( string.Format( Resources.InstantiateFrameworkProviderException, UserServiceLocator == null ? "UserServiceLocator not configured" : UserServiceLocator.GetType().AssemblyQualifiedName, ProviderServiceLocator == null ? "ProviderServiceLocator not configured" : ProviderServiceLocator.GetType().AssemblyQualifiedName)); }