public ServiceProvider(IEnumerable <ServiceDescriptor> serviceDescriptors) { _root = this; _table = new ServiceTable(serviceDescriptors); _table.Add(typeof(IServiceProvider), new ServiceProviderService()); _table.Add(typeof(IServiceScopeFactory), new ServiceScopeService()); _table.Add(typeof(IEnumerable <>), new OpenIEnumerableService(_table)); }
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 providerExpression = Expression.Parameter(typeof(ServiceProvider), "provider"); var lambdaExpression = Expression.Lambda <Func <ServiceProvider, object> >( callSite.Build(providerExpression), providerExpression); table.RealizedServices[serviceType] = lambdaExpression.Compile(); }); } return callSite.Invoke(provider); }); }
// This constructor is called exclusively to create a child scope from the parent internal ServiceProvider(ServiceProvider parent) { _root = parent._root; _table = parent._table; }
public OpenIEnumerableService(ServiceTable table) { _table = table; }