public void RegisterTransient()
        {
            IOne a, b, c, d;

            using (var resolver = new TactContainer(new InMemoryLog()))
            {
                resolver.RegisterTransient <IOne, One>();

                a = resolver.Resolve <IOne>();
                b = resolver.Resolve <IOne>();

                using (var child = resolver.BeginScope())
                {
                    c = child.Resolve <IOne>();
                    d = child.Resolve <IOne>();
                }
            }

            Assert.NotSame(a, b);
            Assert.NotSame(a, c);
            Assert.NotSame(a, d);

            Assert.False(a.IsDisposed);
            Assert.False(b.IsDisposed);
            Assert.False(c.IsDisposed);
            Assert.False(d.IsDisposed);
        }
예제 #2
0
 public void PreventRecursion()
 {
     using (var resolver = new TactContainer(new InMemoryLog()))
     {
         resolver.RegisterTransient <Seven>();
         Assert.Throws <InvalidOperationException>(() => resolver.Resolve <Seven>());
     }
 }
예제 #3
0
        public void GenericInterfaceResolve()
        {
            using (var resolver = new TactContainer(new InMemoryLog()))
            {
                resolver.RegisterTransient(typeof(IEight <>), typeof(Eight <>));

                Assert.Throws <InvalidOperationException>(() => resolver.Resolve <Seven>());

                var eightInt = resolver.Resolve <IEight <int> >();
                Assert.Equal(typeof(int), eightInt.Type);

                var eightBool = resolver.Resolve <IEight <bool> >();
                Assert.Equal(typeof(bool), eightBool.Type);
            }
        }