private void InitializeFields() { if (_builder == null) { _builder = _parent.Builder; } if (_locator == null) { _locator = new Locator(_parent.Locator); } if (!_locator.Contains(typeof(ILifetimeContainer), SearchMode.Local)) { _locator.Add(typeof(ILifetimeContainer), _lifetime); } LocateContainer(typeof(CompositionContainer)); LocateContainer(GetType()); }
static void FindInLocator(Predicate <KeyValuePair <object, object> > predicate, IReadWriteLocator results, IEnumerable <KeyValuePair <object, object> > currentLocator) { foreach (KeyValuePair <object, object> kvp in currentLocator) { if (!results.Contains(kvp.Key) && predicate(kvp)) { results.Add(kvp.Key, kvp.Value); } } }
/// <summary> /// Adds a service that will not be created until the first time it is requested. /// </summary> /// <param name="serviceType">The type of service</param> /// <param name="registerAs">The type to register the service as</param> public void AddOnDemand(Type serviceType, Type registerAs) { Guard.ArgumentNotNull(serviceType, "serviceType"); if (registerAs == null) { registerAs = serviceType; } DependencyResolutionLocatorKey key = new DependencyResolutionLocatorKey(registerAs, null); if (locator.Contains(key, SearchMode.Local)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.DuplicateService, registerAs.FullName)); } DemandAddPlaceholder placeholder = new DemandAddPlaceholder(serviceType); locator.Add(key, placeholder); container.Add(placeholder); }
/// <summary> /// Determines if an object of the given <paramref name="type"/> and with /// the specified <paramref name="objectId"/> exists /// in the container. /// </summary> /// <param name="objectId">The identifier to search for.</param> /// <param name="type">The type of the object to search for.</param> /// <returns><see langword="true"/> if the key exists in the container; <see langword="false"/> otherwise.</returns> public bool Contains(Type type, string objectId) { return(locator.Contains(new DependencyResolutionLocatorKey(type, objectId))); }