public void CanRegisterComponentNamedForMultipleServicesNonGeneric()
        {
            //-- arrange

            IComponentContainerBuilder builderUnderTest = new ComponentContainerBuilder();

            var instanceA = new ComponentOne();
            var instanceB = new ComponentOne();

            //-- act

            builderUnderTest.RegisterComponentInstance(instanceA).NamedForServices("A", typeof(IServiceOne), typeof(ITestComponent));
            builderUnderTest.RegisterComponentInstance(instanceB).NamedForServices("B", typeof(IServiceOne), typeof(ITestComponent));

            var container = ((IInternalComponentContainerBuilder)builderUnderTest).CreateComponentContainer(isRootContainer: true);

            var resolvedA1 = container.ResolveNamed <IServiceOne>("A");
            var resolvedA2 = container.ResolveNamed <ITestComponent>("A");

            var resolvedB1 = container.ResolveNamed <IServiceOne>("B");
            var resolvedB2 = container.ResolveNamed <ITestComponent>("B");

            //-- assert

            resolvedA1.Should().BeSameAs(instanceA);
            resolvedA2.Should().BeSameAs(instanceA);

            resolvedB1.Should().BeSameAs(instanceB);
            resolvedB2.Should().BeSameAs(instanceB);
        }
        public void CanRegisterComponentNamedForThreeServices()
        {
            //-- arrange

            IComponentContainerBuilder builderUnderTest = new ComponentContainerBuilder();

            var instanceA = new ComponentOne();
            var instanceB = new ComponentOne();

            //-- act

            builderUnderTest.RegisterComponentInstance(instanceA).NamedForServices <IServiceOne, ITestComponent, IAnyComponent>("A");
            builderUnderTest.RegisterComponentInstance(instanceB).NamedForServices <IServiceOne, ITestComponent, IAnyComponent>("B");

            var container = ((IInternalComponentContainerBuilder)builderUnderTest).CreateComponentContainer(isRootContainer: true);

            var resolvedA1 = container.ResolveNamed <IServiceOne>("A");
            var resolvedA2 = container.ResolveNamed <IAnyComponent>("A");
            var resolvedA3 = container.ResolveNamed <ITestComponent>("A");

            var resolvedB1 = container.ResolveNamed <IServiceOne>("B");
            var resolvedB2 = container.ResolveNamed <IAnyComponent>("B");
            var resolvedB3 = container.ResolveNamed <ITestComponent>("B");

            //-- assert

            resolvedA1.Should().BeSameAs(instanceA);
            resolvedA2.Should().BeSameAs(instanceA);
            resolvedA3.Should().BeSameAs(instanceA);

            resolvedB1.Should().BeSameAs(instanceB);
            resolvedB2.Should().BeSameAs(instanceB);
            resolvedB3.Should().BeSameAs(instanceB);
        }
Example #3
0
        public void RegisterObjectWithoutExplicitContract()
        {
            var o = new ComponentOne();

            _context.ForObject(o).Register();

            var c = _context.GetComponent <IComponentOne>();

            Assert.IsNotNull(c);
            Assert.IsTrue(ReferenceEquals(c, o));
        }
        public void CanRegisterComponentInstance()
        {
            //-- arrange

            IComponentContainerBuilder builderUnderTest = new ComponentContainerBuilder();
            var componentInstance = new ComponentOne();

            //-- act

            builderUnderTest.RegisterComponentInstance <ComponentOne>(componentInstance);

            //-- assert

            var container = ((IInternalComponentContainerBuilder)builderUnderTest).CreateComponentContainer(isRootContainer: true);
            var resolved  = container.Resolve <ComponentOne>();

            resolved.Should().NotBeNull();
            resolved.Should().BeSameAs(componentInstance);
        }
        public void CanRegisterComponentInstanceForServices()
        {
            //-- arrange

            IComponentContainerBuilder builderUnderTest = new ComponentContainerBuilder();
            var componentInstance = new ComponentOne();

            //-- act

            builderUnderTest.RegisterComponentInstance <ComponentOne>(componentInstance).ForServices <IServiceOne, IAnyComponent>();

            //-- assert

            var container  = ((IInternalComponentContainerBuilder)builderUnderTest).CreateComponentContainer(isRootContainer: true);
            var asService1 = container.Resolve <IServiceOne>();
            var asService2 = container.Resolve <IAnyComponent>();
            var asSelf     = container.Resolve <ComponentOne>();

            asService1.Should().BeSameAs(componentInstance);
            asService2.Should().BeSameAs(componentInstance);
            asSelf.Should().BeSameAs(componentInstance);
        }
 public ComponentThree(ComponentOne one, int number)
 {
     this.One    = one;
     this.Number = number;
 }