private ServiceCallSite[] CreateArgumentCallSites(
            Type serviceType,
            Type implementationType,
            CallSiteChain callSiteChain,
            ParameterInfo[] parameters,
            bool throwIfCallSiteNotFound)
        {
            var parameterCallSites = new ServiceCallSite[parameters.Length];

            for (var index = 0; index < parameters.Length; index++)
            {
                var callSite = GetCallSite(parameters[index].ParameterType, callSiteChain);

                if (callSite == null && ParameterDefaultValue.TryGetDefaultValue(parameters[index], out var defaultValue))
                {
                    callSite = new ConstantCallSite(serviceType, defaultValue);
                }

                if (callSite == null)
                {
                    if (throwIfCallSiteNotFound)
                    {
                        throw new InvalidOperationException(/*Resources.FormatCannotResolveService(
                                                             * parameters[index].ParameterType,
                                                             * implementationType)*/);
                    }

                    return(null);
                }

                parameterCallSites[index] = callSite;
            }

            return(parameterCallSites);
        }
        private ServiceCallSite TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, int slot)
        {
            if (serviceType == descriptor.ServiceType)
            {
                ServiceCallSite callSite;
                var             lifetime = new ResultCache(descriptor.Lifetime, serviceType, slot);
                if (descriptor.ImplementationInstance != null)
                {
                    callSite = new ConstantCallSite(descriptor.ServiceType, descriptor.ImplementationInstance);
                }
                else if (descriptor.ImplementationFactory != null)
                {
                    callSite = new FactoryCallSite(lifetime, descriptor.ServiceType, descriptor.ImplementationFactory);
                }
                else if (descriptor.ImplementationType != null)
                {
                    callSite = CreateConstructorCallSite(lifetime, descriptor.ServiceType, descriptor.ImplementationType, callSiteChain);
                }
                else
                {
                    throw new InvalidOperationException("Invalid service descriptor");
                }

                return(callSite);
            }

            return(null);
        }
Beispiel #3
0
 protected override Type VisitConstant(ConstantCallSite constantCallSite, CallSiteValidatorState state) => null;
 protected override object VisitConstant(ConstantCallSite constantCallSite, RuntimeResolverContext context)
 {
     return(constantCallSite.DefaultValue);
 }
Beispiel #5
0
 protected abstract TResult VisitConstant(ConstantCallSite constantCallSite, TArgument argument);