Ejemplo n.º 1
0
        public void PropertyInjectionCanBeEnabled()
        {
            var builder  = new ContainerBuilder();
            var provider = new AutofacMvxIocProvider(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);
        }
Ejemplo n.º 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 AutofacMvxIocProvider(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);
        }