Ejemplo n.º 1
0
        public void TestMutilConstructor()
        {
            {
                var ioc = new ObjectContainer();
                ioc.AddSingleton <ICache, Redis>();
                ioc.AddTransient <MyService>();

                var svc = ioc.Resolve <MyService>();
                Assert.Equal(1, svc.Kind);
            }

            {
                var ioc = new ObjectContainer();
                ioc.AddSingleton <Redis>();
                ioc.AddTransient <MyService>();

                var svc = ioc.Resolve <MyService>();
                Assert.Equal(2, svc.Kind);
            }

            {
                var ioc = new ObjectContainer();
                ioc.AddSingleton <ICache, Redis>();
                ioc.AddTransient <MyService>();

                var svc = ioc.Resolve <MyService>();
                Assert.Equal(1, svc.Kind);
            }

            {
                var ioc = new ObjectContainer();
                ioc.AddSingleton <ICache, Redis>();
                ioc.AddTransient <MyService>();

                var svc = ioc.Resolve <MyService>();
                Assert.Equal(1, svc.Kind);
            }

            {
                var ioc = new ObjectContainer();
                ioc.AddSingleton <ICache, Redis>();
                ioc.AddSingleton <ILog>(XTrace.Log);
                ioc.AddTransient <MyService>();

                var svc = ioc.Resolve <MyService>();
                Assert.Equal(3, svc.Kind);
            }
        }