Exemplo n.º 1
0
 public void NullSingleton()
 {
     using (var container = new TurboContainer())
     {
         container.AddSingleton <TestClass>((TestClass)null);
         var item = container.Resolve <TestClass>();
         Assert.IsNull(item);
     }
 }
Exemplo n.º 2
0
        public void SimpleResolveTest()
        {
            using (TurboContainer container = new TurboContainer())
            {
                container.AddSingleton <int>(10);
                var result = container.Resolve <int>();

                Assert.AreEqual(10, result);
            }
        }
Exemplo n.º 3
0
        public void SimpleResolveTest2()
        {
            using (var container = new TurboContainer())
            {
                container.AddSingleton <int>(10);
                container.AddSingleton <string>("value");
                container.AddPerCall <ITestInterface, TestImplementation>();
                container.AddAssociation <TestClass, TestClass>(LifetimeFactories.DeferedSingleton);
                container.AddAssociation <double>(new PerCallLifetime(typeof(double), r => 15.0));

                Assert.AreEqual("value", container.Resolve <string>());
                Assert.IsInstanceOfType(container.Resolve <ITestInterface>(), typeof(TestImplementation));

                var obj = container.CreateObject <TestInjectionToConstructor>();
                Assert.IsNotNull(obj);
                Assert.AreEqual(15.0, obj.Value);
                Assert.AreEqual("value", obj.StrValue);
                Assert.IsNotNull(container.Resolve <TestClass>());
            }
        }
Exemplo n.º 4
0
        public void ResolveTheBaseClass()
        {
            using (var container = new TurboContainer())
            {
                container.AddSingleton <TestClass>(new TestDerivedClass());
                var item = container.Resolve <TestClass>();
                Assert.IsNotNull(item);

                container.RemoveAssociation <TestClass>();

                container.AddDeferedSingleton <TestClass, TestDerivedClass>();
                var item2 = container.Resolve <TestClass>();
                Assert.IsNotNull(item2);
            }
        }