Esempio n. 1
0
        public object Activate(Type concreteType, IContainer container, IResolvingContext context)
        {
            var t = _lambda(container);

            if (t is IDisposable)
            {
                container.AddDisposable((IDisposable)t);
            }
            return(t);
        }
Esempio n. 2
0
        public object Activate(
            Type concreteType,
            IContainer container,
            IResolvingContext context)
        {
            // Freshly construct the instance
            var constructor        = concreteType.GetConstructors().First();
            var resolvedParameters = constructor
                                     .GetParameters()
                                     .Select(parameterInfo => ProvideParameterValue(container, context, parameterInfo))
                                     .ToArray();
            var inst = constructor.Invoke(resolvedParameters);

            if (inst is IDisposable)
            {
                container.AddDisposable((IDisposable)inst);
            }
            return(inst);
        }
Esempio n. 3
0
        object ProvideParameterValue(
            IContainer container,
            IResolvingContext context,
            ParameterInfo parameterInfo)
        {
            // Search to find the first value provider that match this parameter
            for (var i = 0; i < _parameterResolvers.Count; i++)
            {
                if (_parameterResolvers[i].Match(parameterInfo))
                {
                    var inst = _parameterResolvers[i].ValueProvider(parameterInfo, container);
                    if (inst is IDisposable)
                    {
                        container.AddDisposable((IDisposable)container);
                    }
                    return(inst);
                }
            }

            // Use the container to resolve the parameter by default
            return(container.Resolve(parameterInfo.ParameterType, context));
        }