Exemple #1
0
        public void TestContainerResolveInstance()
        {
            var container = new TinyContainer();

            container.RegisterTransient <SimpleDependency>();

            var dependency1 = container.Resolve <SimpleDependency>();

            Assert.IsNotNull(dependency1);
            Assert.IsInstanceOfType(dependency1, typeof(SimpleDependency));

            Assert.AreEqual(SimpleDependency.ActiveDependecies, 1);
            Assert.AreEqual(SimpleDependency.ResolveCounter, 1);

            var dependency2 = container.Resolve <SimpleDependency>();

            Assert.IsNotNull(dependency2);
            Assert.IsInstanceOfType(dependency2, typeof(SimpleDependency));

            Assert.AreEqual(SimpleDependency.ActiveDependecies, 2);
            Assert.AreEqual(SimpleDependency.ResolveCounter, 2);

            Assert.AreNotSame(dependency1, dependency2);

            container.Dispose();

            Assert.AreEqual(SimpleDependency.ActiveDependecies, 0);
        }
        public void TestResolitionWithAutowiring()
        {
            var container = new TinyContainer();

            container.RegisterTransient <ITestDependency, SimpleDependency>()
            .RegisterTransient <CompositeDependecy>();

            var dependency = container.Resolve <CompositeDependecy>();

            Assert.IsNotNull(dependency);
            Assert.IsInstanceOfType(dependency, typeof(CompositeDependecy));

            Assert.IsNotNull(dependency.InnerDependency);
            Assert.IsInstanceOfType(dependency.InnerDependency, typeof(SimpleDependency));

            container.Dispose();

            Assert.IsNull(dependency.InnerDependency); // Checking that dependecny was disposed
        }