コード例 #1
0
        public void TestResolveSingleton()
        {
            _container.Register <IBar, IFoo, IAnotherFoo, IAnotherBar, IAnotherOne, Foo>(Lifestyle.Singleton);
            IFoo        foo        = _container.Resolve <IFoo>();
            IBar        bar        = _container.Resolve <IBar>();
            IAnotherFoo anotherFoo = _container.Resolve <IAnotherFoo>();
            IAnotherBar anotherBar = _container.Resolve <IAnotherBar>();
            IAnotherOne anotherOne = _container.Resolve <IAnotherOne>();

            Assert.IsInstanceOf <Foo>(foo);
            Assert.IsInstanceOf <Foo>(bar);
            Assert.IsInstanceOf <Foo>(anotherFoo);
            Assert.IsInstanceOf <Foo>(anotherBar);
            Assert.IsInstanceOf <Foo>(anotherOne);

            Assert.AreEqual(foo, bar);
            Assert.AreEqual(foo, anotherFoo);
            Assert.AreEqual(foo, anotherBar);
            Assert.AreEqual(foo, anotherOne);

            Assert.AreSame(foo, bar);
            Assert.AreSame(foo, anotherFoo);
            Assert.AreSame(foo, anotherBar);
            Assert.AreSame(foo, anotherOne);
        }
コード例 #2
0
        public void TestResolveTransient()
        {
            _container.Register <IBar, IFoo, IAnotherFoo, IAnotherBar, IAnotherOne, Foo>();
            IFoo        foo        = _container.Resolve <IFoo>();
            IBar        bar        = _container.Resolve <IBar>();
            IAnotherFoo anotherFoo = _container.Resolve <IAnotherFoo>();
            IAnotherBar anotherBar = _container.Resolve <IAnotherBar>();
            IAnotherOne anotherOne = _container.Resolve <IAnotherOne>();

            Assert.IsInstanceOf <Foo>(foo);
            Assert.IsInstanceOf <Foo>(bar);
            Assert.IsInstanceOf <Foo>(anotherFoo);
            Assert.IsInstanceOf <Foo>(anotherBar);
            Assert.IsInstanceOf <Foo>(anotherOne);
        }