Exemple #1
0
        protected override Func <PipelineResult> Invoker(Type type, PipelineResult result)
        {
            return(() =>
            {
                if (result == null)
                {
                    return null;
                }

                IList <IRegistration> actions = null;

                if (registrationStore.Contains(result.MappedTo))
                {
                    actions = registrationStore.GetRegistrationsForType(result.MappedTo);
                }
                else if (registrationStore.Contains(result.MappedFrom))
                {
                    actions = registrationStore.GetRegistrationsForType(result.MappedFrom);
                }

                if (actions != null)
                {
                    for (int i = 0; i < actions.Count; i++)
                    {
                        var actionRegistration = actions[i];
                        result.Result = actionRegistration.ResolveWith(new ValueResolver(result.Result), store, null);
                    }
                }

                return result;
            });
        }
Exemple #2
0
        public override PipelineResult Execute(Type requestedType, PipelineResult value)
        {
            if (value != null && value.Result != null)
            {
                return(value);
            }

            var result = new PipelineResult();
            var type   = requestedType;

            if (serviceLocator.HasTypeRegistered(type) || type.IsGenericType)
            {
                result.Name       = value == null ? null : value.Name;
                result.MappedFrom = requestedType;
                result.MappedTo   = type;

                var items = store.Get <IResolutionStore>().Items;

                if (result.Name == null)
                {
                    result.Result = serviceLocator.GetInstance(type, items.OfType <ConstructorParameter, IResolutionArgument>());
                }
                else
                {
                    result.Result = serviceLocator.GetInstance(type, result.Name, items.OfType <ConstructorParameter, IResolutionArgument>());
                }

                result = pipeline.Execute(result);

                return(result);
            }

            return(null);
        }
        public override PipelineResult Execute(Type requestedType, PipelineResult value)
        {
            if (value != null && value.Result != null) return value;

            var result = new PipelineResult();
            var type = requestedType;

            if (serviceLocator.HasTypeRegistered(type) || type.IsGenericType)
            {
                result.Name = value == null ? null : value.Name;
                result.MappedFrom = requestedType;
                result.MappedTo = type;

                var items = store.Get<IResolutionStore>().Items;

                if(result.Name == null)
                {
                    result.Result = serviceLocator.GetInstance(type, items.OfType<ConstructorParameter, IResolutionArgument>());
                }
                else
                {
                    result.Result = serviceLocator.GetInstance(type, result.Name,items.OfType<ConstructorParameter, IResolutionArgument>());
                }

                result = pipeline.Execute(result);

                return result;
            }

            return null;
        }
        protected override Func <PipelineResult> Invoker(Type type, PipelineResult value)
        {
            return(() =>
            {
                if (value != null && value.Result != null)
                {
                    return value;
                }

                var result = new PipelineResult();
                IList <IRegistration> conditionalCases = registrationStore.GetRegistrationsForType(type);

                if (conditionalCases == null)
                {
                    return null;
                }

                for (int i = 0; i < conditionalCases.Count; i++)
                {
                    var registration = conditionalCases[i];

                    if (registration.IsValid(serviceLocator, store))
                    {
                        var mappedToType = registration.GetMappedToType();
                        if (TypeRequested != null)
                        {
                            TypeRequested(mappedToType);
                        }

                        result.Name = registration is INamedRegistration
                                          ? ((INamedRegistration)registration).Key
                                          : null;
                        result.MappedTo = mappedToType;
                        result.MappedFrom = registration.GetMappedFromType();
                        result.Result = Resolve(registration);

                        if (result.Result != null && TypeResolved != null)
                        {
                            TypeResolved(type);
                        }

                        if (result.Result != null)
                        {
                            result = pipeline.Execute(result);
                        }
                        return result;
                    }
                }

                return null;
            });
        }
        public PipelineResult Execute(PipelineResult result)
        {
            var tempValue = result.Result;
            var value = result.Result;

            if (value == null) return result;

            result = Items.Aggregate(result, (current, item) => item.Execute(value.GetType(), current));

            if (value == null) throw new RegistrationNotFoundException(tempValue.GetType());

            return result;
        }
Exemple #6
0
        public object Execute(Type type)
        {
            PipelineResult value = null;

            value = items.Aggregate(value, (current, item) => item.Execute(type, current));

            if (value == null)
            {
                throw new RegistrationNotFoundException(type);
            }
            if (value.Result == null)
            {
                throw new RegistrationNotFoundException(type);
            }

            return(value.Result);
        }
Exemple #7
0
        protected override Func <PipelineResult> Invoker(Type type, PipelineResult value)
        {
            return(() =>
            {
                if (value != null && value.Result != null)
                {
                    return value;
                }

                var result = new PipelineResult();

                var registrations = registrationStore.GetRegistrationsForType(type);

                if (registrations == null)
                {
                    return null;
                }

                var mappedToType = registrations[0].GetMappedToType();
                if (TypeRequested != null)
                {
                    TypeRequested(mappedToType);
                }

                result.Name = registrations[0] is INamedRegistration
                                  ? ((INamedRegistration)registrations[0]).Key
                                  : null;
                result.MappedTo = mappedToType;
                result.MappedFrom = registrations[0].GetMappedFromType();
                result.Result = Resolve(registrations[0]);

                if (result.Result != null)
                {
                    result = pipeline.Execute(result);
                }

                if (result.Result != null && TypeResolved != null)
                {
                    TypeResolved(type);
                }

                return result;
            });
        }
        public PipelineResult Execute(PipelineResult result)
        {
            var tempValue = result.Result;
            var value     = result.Result;

            if (value == null)
            {
                return(result);
            }

            result = Items.Aggregate(result, (current, item) => item.Execute(value.GetType(), current));

            if (value == null)
            {
                throw new RegistrationNotFoundException(tempValue.GetType());
            }

            return(result);
        }
Exemple #9
0
 public abstract PipelineResult Execute(Type requestedType, PipelineResult result);
Exemple #10
0
 public abstract PipelineResult Execute(Type requestedType, PipelineResult result);