public void CanAddInstancesDirectlyToAnInstanceFactory()
        {
            IInstanceFactory factory = getISomethingFactory();

            factory.AddInstance(new ObjectInstance(_red).WithName("Red"));
            factory.AddInstance(new ObjectInstance(_blue).WithName("Blue"));

            factory.FindInstance("Red").ShouldNotBeNull();
        }
Пример #2
0
        public void the_instances_are_cloned_so_that_new_instances_are_NOT_injected_into_()
        {
            clone.AddInstance(new ObjectInstance(new DefaultGateway()));

            factory.AllInstances.Count().ShouldEqual(2);
            clone.AllInstances.Count().ShouldEqual(3);
        }
        public void NowOverwriteAPreviouslyAttachedInstance()
        {
            IInstanceFactory factory = getISomethingFactory();

            factory.AddInstance(new ObjectInstance(_red).WithName("Red"));
            ObjectInstance oldBlue = new ObjectInstance(_blue).WithName("Blue");

            factory.AddInstance(oldBlue);

            // Replace Blue
            ObjectInstance newBlue = new ObjectInstance(_orange).WithName("Blue");

            factory.AddInstance(newBlue);

            factory.FindInstance("Blue").ShouldBeTheSameAs(newBlue);

            factory.AllInstances.Contains(oldBlue).ShouldBeFalse();
        }