Ejemplo n.º 1
0
        public MethodMaterializer(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");
            Assume.ArgumentNotNull(context.Instance, "context.Instance");

            this.context = context;
        }
Ejemplo n.º 2
0
        public override ConstructorInfo Selecter(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            var bindingFlags             = new BindingFlagsCombiner().Execute(context.Container.Options.ResolvePrivateMembers);
            var constructors             = new List <ConstructorInfo>(context.TypeToResolve.GetConstructors(bindingFlags));
            var injectMarkedConstructors = constructors.FindAll(constructor => constructor.IsDefined(typeof(InjectAttribute), false));

            if (injectMarkedConstructors.Count > 1)
            {
                throw new NotSupportedException(Strings.MultipleConstructorInjectionIsNotSupported);
            }

            if (injectMarkedConstructors.Count == 1)
            {
                return(injectMarkedConstructors[0]);
            }

            if (constructors.Count > 0)
            {
                return(constructors[0]);
            }

            return(context.TypeToResolve.GetConstructor(Type.EmptyTypes));
        }
Ejemplo n.º 3
0
        public PropertyInjector(PropertyInfo property, IShifterContext context, object value)
        {
            Assume.ArgumentNotNull(property, "property");
            Assume.ArgumentNotNull(context, "context");

            this.property = property;
            this.context  = context;
            this.value    = value;
        }
Ejemplo n.º 4
0
        public override IEnumerable <PropertyInfo> Select(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            var bindingFlags = new BindingFlagsCombiner().Execute(context.Container.Options.ResolvePrivateMembers);
            var propertyList = new List <PropertyInfo>(context.TypeToResolve.GetProperties(bindingFlags));

            return(propertyList.Where(property => property.IsDefined(typeof(InjectAttribute), false)));
        }
Ejemplo n.º 5
0
        public ConstructorInjector(ConstructorInfo constructor, IShifterContext context, object[] arguments)
        {
            Assume.ArgumentNotNull(constructor, "constructor");
            Assume.ArgumentNotNull(context, "context");

            this.constructor = constructor;
            this.context     = context;
            this.arguments   = arguments;
        }
Ejemplo n.º 6
0
        public MethodInjector(IShifterContext context, MethodBase method, object[] parameters)
        {
            Assume.ArgumentNotNull(context, "context");
            Assume.ArgumentNotNull(method, "method");
            Assume.ArrayNotNullOrEmpty(parameters, "parameters");

            this.context    = context;
            this.method     = method;
            this.parameters = parameters;
        }
Ejemplo n.º 7
0
        public FieldInjector(IShifterContext context, FieldInfo field, object value)
        {
            Assume.ArgumentNotNull(context, "context");
            Assume.ArgumentNotNull(field, "field");
            Assume.ArgumentNotNull(value, "value");

            this.context = context;
            this.field   = field;
            this.value   = value;
        }
Ejemplo n.º 8
0
        public ShifterContext(Type typeToResolve, IShifterContainer container, IEnumerable <Func <IResolutionStrategy> > strategyFactoryFactories)
        {
            Assume.ArgumentNotNull(typeToResolve, "typeToResolve");
            Assume.ArgumentNotNull(container, "container");
            Assume.ArgumentNotNull(strategyFactoryFactories, "strategyFactoryFactories");

            TypeToResolve     = typeToResolve;
            Container         = container;
            StrategyFactories = strategyFactoryFactories;
        }
Ejemplo n.º 9
0
        public void Initialize(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            if (context.Instance == null)
            {
                throw new TypeResolvingFailedException(string.Format(Strings.InstanceIsNull, context.TypeToResolve.Name));
            }

            InitializeImpl(context);
        }
Ejemplo n.º 10
0
        public PropertyMaterializer(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            this.context = context;
        }