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 BuildType(callSite);
        }
Example #2
0
        internal static Func <ServiceProvider, object> RealizeService(ServiceTable table, Type serviceType, IServiceCallSite callSite)
        {
            var callCount = 0;

            return(provider => {
                if (Interlocked.Increment(ref callCount) == 2)
                {
                    Task.Run(() => {
                        var realizedService = new CallSiteExpressionBuilder(_callSiteRuntimeResolver)
                                              .Build(callSite);
                        table.RealizedServices[serviceType] = realizedService;
                    });
                }

                return _callSiteRuntimeResolver.Resolve(callSite, provider);
            });
        }
Example #3
0
 private static object Invoke(ServiceCallSite callSite, ServiceProviderEngineScope scope)
 {
     return(CallSiteRuntimeResolver.Resolve(callSite, scope));
 }
Example #4
0
 private static object Invoke(IServiceCallSite callSite, ServiceProviderEngine provider)
 {
     return(CallSiteRuntimeResolver.Resolve(callSite, provider.Root));
 }