Exemple #1
0
        public void RequestingTypeMappingOnChildReadsFromParent()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            parent.RegisterTypeMapping <IFoo, Foo>();

            Assert.AreEqual(typeof(Foo), child.GetMappedType <IFoo>());
        }
Exemple #2
0
        public void ChildContainersCanOverrideParentTypeMapping()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            parent.RegisterTypeMapping <IFoo, Foo>();
            child.RegisterTypeMapping <IFoo, Foo2>();

            Assert.AreEqual(typeof(Foo), parent.GetMappedType <IFoo>());
            Assert.AreEqual(typeof(Foo2), child.GetMappedType <IFoo>());
        }
        /// <summary>
        /// Maps one type/ID pair to another, using the locator to find the
        /// current <see cref="CompositionContainer"/>. The container holds
        /// the current set of type mappings.
        /// </summary>
        /// <param name="locator">The <see cref="IReadableLocator"/> being used in the
        /// current BuildUp operation.</param>
        /// <param name="incomingTypeIdPair"><see cref="DependencyResolutionLocatorKey"/> that identifies
        /// the type of the current BuildUp operation.</param>
        /// <returns>The new type to return; returns the original key if no type mapping is defined.</returns>
        public DependencyResolutionLocatorKey Map(
            IReadableLocator locator, DependencyResolutionLocatorKey incomingTypeIdPair)
        {
            DependencyResolutionLocatorKey result    = incomingTypeIdPair;
            CompositionContainer           container = GetCompositionContainerFromLocator(locator);

            if (container != null)
            {
                result = new DependencyResolutionLocatorKey(container.GetMappedType(result.Type),
                                                            incomingTypeIdPair.ID);
            }
            return(result);
        }