示例#1
0
        public void OptionalParametersSetToNullIfNotRegistered()
        {
            IUnityContainer container = new UnityContainer();

            OptionalConstParameterClass result = container.Resolve <OptionalConstParameterClass>();

            Assert.IsNull(result.TestObject);
        }
示例#2
0
        public void OptionalParametersNotResolvedIfMoreSpecificTypeRegistered()
        {
            IUnityContainer container = new UnityContainer();
            var             input     = new TestObject();

            container.RegisterInstance <TestObject>(input);

            OptionalConstParameterClass result = container.Resolve <OptionalConstParameterClass>();

            Assert.IsNull(result.TestObject);
        }
示例#3
0
        public void OptionalParametersResolvedIfInstanceRegistered()
        {
            IUnityContainer container = new UnityContainer();
            var             input     = new TestObject();

            container.RegisterInstance <ITestObject>(input);

            OptionalConstParameterClass result = container.Resolve <OptionalConstParameterClass>();

            Assert.AreSame(input, result.TestObject);
        }
示例#4
0
        public void OptionalParametersResolvedIfInstanceRegisteredInParent()
        {
            IUnityContainer parent = new UnityContainer();
            IUnityContainer child  = parent.CreateChildContainer();

            var input = new TestObject();

            parent.RegisterInstance <ITestObject>(input);

            OptionalConstParameterClass result = child.Resolve <OptionalConstParameterClass>();

            Assert.AreSame(input, result.TestObject);
        }