Ejemplo n.º 1
0
        private void ValidateService(ServiceDescriptor descriptor)
        {
            if (descriptor.ServiceType.IsGenericType && !descriptor.ServiceType.IsConstructedGenericType)
            {
                return;
            }

            try
            {
                ServiceCallSite?callSite = CallSiteFactory.GetCallSite(descriptor, new CallSiteChain());
                if (callSite != null)
                {
                    OnCreate(callSite);
                }
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"Error while validating the service descriptor '{descriptor}': {e.Message}", e);
            }
        }
Ejemplo n.º 2
0
        private Func <ServiceProviderEngineScope, object?> CreateServiceAccessor(Type serviceType)
        {
            ServiceCallSite?callSite = CallSiteFactory.GetCallSite(serviceType, new CallSiteChain());

            if (callSite != null)
            {
                DependencyInjectionEventSource.Log.CallSiteBuilt(this, serviceType, callSite);
                OnCreate(callSite);

                // Optimize singleton case
                if (callSite.Cache.Location == CallSiteResultCacheLocation.Root)
                {
                    object?value = CallSiteRuntimeResolver.Instance.Resolve(callSite, Root);
                    return(scope => value);
                }

                return(_engine.RealizeService(callSite));
            }

            return(_ => null);
        }