示例#1
0
        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 ShouldStoreByTypeIfASpecificTypeIsProvided()
        {
            var container = new SimpleInjector();
            Cat cat       = new Cat();

            container.Store(cat, typeof(Animal));

            var catFromStore = container.FindByType <Animal>();

            Assert.Same(cat, catFromStore);
        }
        public void ShouldStoreAPreBakedObjectWithoutConfiguringItsDependencies()
        {
            var container = new SimpleInjector();
            var house     = new House();

            container.Store(house);

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

            Assert.NotNull(houseFromContainer);
            Assert.Null(house.Room);
        }
        public void ShouldStoreAndLoadCollectionTypes()
        {
            var container = new SimpleInjector();
            var houses    = new List <House> {
                new House(), new House(), new House()
            };

            container.Store(houses);

            var housesFromStore = container.FindByType <List <House> >();

            Assert.Same(houses, housesFromStore);
        }
        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);
        }