internal IServiceCallSite GetServiceCallSite(Type serviceType, ISet <Type> callSiteChain) { try { if (callSiteChain.Contains(serviceType)) { throw new InvalidOperationException(Resources.FormatCircularDependencyException(serviceType)); } callSiteChain.Add(serviceType); ServiceEntry entry; if (_table.TryGetEntry(serviceType, out entry)) { return(GetResolveCallSite(entry.Last, callSiteChain)); } object emptyIEnumerableOrNull = GetEmptyIEnumerableOrNull(serviceType); if (emptyIEnumerableOrNull != null) { return(new EmptyIEnumerableCallSite(serviceType, emptyIEnumerableOrNull)); } return(null); } finally { callSiteChain.Remove(serviceType); } }
/// <summary> /// Gets the service object of the specified type. /// </summary> /// <param name="serviceType"></param> /// <returns></returns> public object GetService(Type serviceType) { ServiceEntry entry; if (_table.TryGetEntry(serviceType, out entry)) { return(ResolveService(entry.Last)); } object service = GetFallbackService(serviceType) ?? GetEmptyIEnumerableOrNull(serviceType); if (service == null) { throw new Exception( string.Format("TODO: No service for type '{0}' has been registered.", serviceType)); } return(service); }