예제 #1
0
        public void ComponentIsResolved()
        {
            var config = new ComponentConfig();

            config.Add <SimpleObject>();

            using var container = config.ToContainer();
            var obj = container.Get <SimpleObject>();

            Assert.NotNull(obj);
        }
예제 #2
0
        public void ComponentIsResolvedSameObject()
        {
            var config = new ComponentConfig();

            config.Add <SimpleObject>();

            using var container = config.ToContainer();
            var obj1 = container.Get <SimpleObject>();
            var obj2 = container.GetService(typeof(SimpleObject));

            Assert.Same(obj1, obj2);
        }
예제 #3
0
        public void ComponentIsMultipleResolvedByGetService()
        {
            var config = new ComponentConfig();

            config.Add <ICalcService, AddCalcService>();
            config.Add <ICalcService, SubCalcService>();

            using var container = config.ToContainer();
            var services = (IEnumerable <ICalcService>?)container.GetService(typeof(IEnumerable <ICalcService>));

            Assert.Equal(2, services?.Count());
        }
예제 #4
0
        public void ComponentIsMultipleResolved()
        {
            var config = new ComponentConfig();

            config.Add <ICalcService, AddCalcService>();
            config.Add <ICalcService, SubCalcService>();

            using var container = config.ToContainer();
            var services = container.GetAll <ICalcService>();

            Assert.Equal(2, services.Count());
        }
예제 #5
0
        public void ComponentIsResolvedByDefaultConstructor()
        {
            var config = new ComponentConfig();

            config.Add <MultiConstructorObject>();

            using var container = config.ToContainer();
            var obj = container.Get <MultiConstructorObject>();

            Assert.Equal(0, obj.Arguments);
            Assert.Null(obj.CalcService);
        }
예제 #6
0
        public void ComponentIsResolvedWithMultipleArgument()
        {
            var config = new ComponentConfig();

            config.Add <ArrayParameterObject>();
            config.Add <ICalcService, AddCalcService>();
            config.Add <ICalcService, SubCalcService>();

            using var container = config.ToContainer();
            var obj = container.Get <ArrayParameterObject>();

            Assert.Equal(2, obj.CalcServices.Length);
        }
예제 #7
0
        public void ComponentIsDisposed()
        {
            var config = new ComponentConfig();

            config.Add <DisposableObject>();

            DisposableObject obj;

            using (var container = config.ToContainer())
            {
                obj = container.Get <DisposableObject>();
            }

            Assert.Equal(1, obj.Disposed);
        }