Пример #1
0
        private static void CountReturnsNumberOfKeysWithLiveValues_TestHelper(IReadWriteLocator locator)
        {
            object o = new object();

            locator.Add("foo1", o);
            locator.Add("foo2", o);

            Assert.AreEqual(2, locator.Count);
        }
Пример #2
0
 private BuilderContainer(BuilderContainer parent)
 {
     builder  = new BuilderBase <BuilderStage>(parent.configurator);
     lifetime = new LifetimeContainer();
     locator  = new Locator(parent.locator);
     locator.Add(typeof(ILifetimeContainer), lifetime);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="LocatorNameTypeFactoryBase{T}"/> class with a configuration source
        /// and a locator.
        /// </summary>
        /// <param name="configurationSource">The configuration source to use.</param>
        protected LocatorNameTypeFactoryBase(IConfigurationSource configurationSource)
        {
            this.configurationSource = configurationSource;

            locator           = new Locator();
            lifetimeContainer = new LifetimeContainer();
            locator.Add(typeof(ILifetimeContainer), lifetimeContainer);
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the container using the specified configurator.
        /// </summary>
        /// <param name="configurator">The configurator that provides default
        /// strategies for the container.</param>
        public BuilderContainer(IBuilderConfigurator <BuilderStage> configurator)
        {
            Guard.ArgumentNotNull(configurator, "configurator");

            lifetime = new LifetimeContainer();
            locator  = new Locator();
            locator.Add(typeof(ILifetimeContainer), lifetime);
            builder           = new BuilderBase <BuilderStage>(configurator);
            this.configurator = configurator;
        }
        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());
        }
Пример #6
0
 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);
         }
     }
 }
Пример #7
0
        /// <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);
        }
 public TestableServiceCollection(TestableServiceCollection parent)
     : this(parent.container, new Locator(parent.locator), parent.builder, parent)
 {
     locator.Add(typeof(ILifetimeContainer), parent.locator.Get <ILifetimeContainer>());
 }
 /// <summary>
 /// Used to "build" an item we've already seen once. We don't use the builder, because that
 /// would do double-injection. Since it's already in the lifetime container, all we need to
 /// do is add a second locator registration for it for the right name.
 /// </summary>
 private void BuildRepeatedItem(Type typeToBuild, string idToBuild, object item)
 {
     locator.Add(new DependencyResolutionLocatorKey(typeToBuild, NormalizeID(idToBuild)), item);
 }
 public TestableManagedObjectCollection(TestableManagedObjectCollection <TItem> parent)
     : this(parent.container, new Locator(parent.locator), parent.builder, parent.searchMode,
            parent.indexerCreationDelegate, parent.predicate, parent)
 {
     locator.Add(typeof(ILifetimeContainer), parent.locator.Get <ILifetimeContainer>());
 }
Пример #11
0
 private static void RegistrationDoesNotPreventGarbageCollection_TestHelper(IReadWriteLocator locator)
 {
     locator.Add("foo", new object());
 }