public static void Main()
        {
            SimpleInjector injector = new SimpleInjector();

            injector.Store(Console.Out, typeof(TextWriter));
            injector.Store(Console.In, typeof(TextReader));

            injector.Configure <ListTicketsScreen>();
            injector.Configure <AddTicketScreen>();
            injector.Configure <EditTicketScreen>();
            injector.Configure <RemoveTicketScreen>();

            injector.Store(new List <IScreen>
            {
                injector.FindByType <ListTicketsScreen>(),
                injector.FindByType <AddTicketScreen>(),
                injector.FindByType <EditTicketScreen>(),
                injector.FindByType <RemoveTicketScreen>()
            }, typeof(ICollection <IScreen>));

            injector.Configure <ScreenManager>();

            var screenManager = injector.FindByType <ScreenManager>();

            screenManager.StartInputOutputLoop().Wait();
        }
        public void ShouldCreateOneInstanceAndShareItWithOtherConfiguredObjects()
        {
            var container = new SimpleInjector();

            container.Configure <House>();
            container.Configure <Office>();

            Room houseRoom  = container.FindByType <House>().Room;
            Room officeRoom = container.FindByType <Office>().ConferenceRoom;

            Assert.Same(houseRoom, officeRoom);
        }
        public void ShouldDoNothingIfMoreThanOneAttemptIsMadeToCreateAnInstance()
        {
            var container = new SimpleInjector();

            container.Configure <House>();

            var house = container.FindByType <House>();

            container.Configure <House>();

            var secondHouse = container.FindByType <House>();

            Assert.Same(house, secondHouse);
        }
        public void ShouldCreateAnInstanceAndRetrieveByType()
        {
            var container = new SimpleInjector();

            container.Configure <House>();

            var actualInstance = container.FindByType <House>();

            Assert.NotNull(actualInstance);
        }
        public void ShouldRecursivelyConfigureProperties()
        {
            var container = new SimpleInjector();

            container.Configure <House>();

            Window window = container.FindByType <House>().Room.Window;

            Assert.NotNull(window);
        }
        public void ShouldStoreInstancesCreatedForProperties()
        {
            var container = new SimpleInjector();

            container.Configure <House>();

            var actualInstance = container.FindByType <Room>();

            Assert.NotNull(actualInstance);
        }
        public void ShouldSkipReadOnlyPropertiesAndNotThrowException()
        {
            var container = new SimpleInjector();

            container.Configure <ReadOnlyFoo>();

            var actualInstance = container.FindByType <ReadOnlyFoo>();

            Assert.Null(actualInstance.Window);
        }
        public void ShouldNotAutomaticallyConfigureDotNetTypedDependenciesIfNoMatchesAreAvailable()
        {
            var container = new SimpleInjector();

            container.Configure <Block>();

            var block = container.FindByType <Block>();

            Assert.Null(block.Houses);
        }
        public void ShouldConfigureDotNetTypesIfAndOnlyIfAMatchIsAvailable()
        {
            var container = new SimpleInjector();
            var houses    = new List <House> {
                new House(), new House(), new House()
            };

            container.Store(houses);

            container.Configure <Block>();

            var block = container.FindByType <Block>();

            Assert.Same(houses, block.Houses);
        }