Ejemplo n.º 1
0
        public Func <ServiceProviderEngineScope, object> Build(ServiceCallSite callSite)
        {
            // Optimize singleton case
            if (callSite.Cache.Location == CallSiteResultCacheLocation.Root)
            {
                object value = _runtimeResolver.Resolve(callSite, _rootScope);
                return(scope => value);
            }

            // Only scope methods are cached
            if (callSite.Cache.Location == CallSiteResultCacheLocation.Scope)
            {
#if NETSTANDARD2_1
                return(_scopeResolverCache.GetOrAdd(callSite.Cache.Key, _buildTypeDelegate, callSite));
#else
                return(_scopeResolverCache.GetOrAdd(callSite.Cache.Key, key => _buildTypeDelegate(key, callSite)));
#endif
            }

            return(BuildNoCache(callSite));
        }
Ejemplo n.º 2
0
        public Func <ServiceProviderEngineScope, object> Build(IServiceCallSite callSite)
        {
            if (callSite is SingletonCallSite singletonCallSite)
            {
                // If root call site is singleton we can return Func calling
                // _runtimeResolver.Resolve directly and avoid Expression generation
                if (TryResolveSingletonValue(singletonCallSite, out var value))
                {
                    return(scope => value);
                }

                return(scope => _runtimeResolver.Resolve(callSite, scope));
            }

            return(BuildType(callSite));
        }
Ejemplo n.º 3
0
        public Func <ServiceProviderEngineScope, object> Build(ServiceCallSite callSite)
        {
            if (callSite.Cache.Location == CallSiteResultCacheLocation.Root)
            {
                // If root call site is singleton we can return Func calling
                // _runtimeResolver.Resolve directly and avoid Expression generation
                if (TryResolveSingletonValue(callSite, out var value))
                {
                    return(scope => value);
                }

                return(scope => _runtimeResolver.Resolve(callSite, scope));
            }

            return(BuildExpression(callSite).Compile());
        }
Ejemplo n.º 4
0
        public Func <ServiceProviderEngineScope, object> Build(ServiceCallSite callSite)
        {
            if (callSite.Cache.Location == CallSiteResultCacheLocation.Root)
            {
                // If root call site is singleton we can return Func calling
                // _runtimeResolver.Resolve directly and avoid Expression generation
                if (TryResolveSingletonValue(callSite, out var value))
                {
                    return(scope => value);
                }

                return(scope => _runtimeResolver.Resolve(callSite, scope));
            }

            var expression = BuildExpression(callSite);

            DependencyInjectionEventSource.Log.ExpressionTreeGenerated(callSite.ServiceType, expression);
            return(expression.Compile());
        }