예제 #1
0
        public void PropertyInjectionCanBeEnabled()
        {
            var builder  = new ContainerBuilder();
            var provider = new ChildAutofacMvxIocProvider(builder.Build(), new AutofacPropertyInjectorOptions {
                InjectIntoProperties = MvxPropertyInjection.AllInterfaceProperties
            });

            this._disposables.Add(provider);
            provider.RegisterType(() => new Concrete());
            provider.RegisterType(typeof(Exception), () => new DivideByZeroException());
            var resolved = provider.Resolve <Concrete>();

            // Default behavior is to inject all unset properties.
            Assert.IsType <DivideByZeroException>(resolved.PropertyToInject);
            Assert.IsType <DivideByZeroException>(resolved.PropertyToSkip);
        }
예제 #2
0
        public void PropertyInjectionCanBeCustomized()
        {
            var builder = new ContainerBuilder();
            var options = new AutofacPropertyInjectorOptions
            {
                InjectIntoProperties      = MvxPropertyInjection.AllInterfaceProperties,
                PropertyInjectionSelector = new DelegatePropertySelector((pi, obj) => pi.Name != "PropertyToSkip"),
            };
            var provider = new ChildAutofacMvxIocProvider(builder.Build(), options);

            this._disposables.Add(provider);
            provider.RegisterType(() => new Concrete());
            provider.RegisterType(typeof(Exception), () => new DivideByZeroException());
            var resolved = provider.Resolve <Concrete>();

            Assert.IsType <DivideByZeroException>(resolved.PropertyToInject);
            Assert.Null(resolved.PropertyToSkip);
        }