Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 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 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);
            });
        }
Ejemplo n.º 3
0
 // This constructor is called exclusively to create a child scope from the parent
 internal ServiceProvider(ServiceProvider parent)
 {
     _root  = parent._root;
     _table = parent._table;
 }
Ejemplo n.º 4
0
 public OpenIEnumerableService(ServiceTable table)
 {
     _table = table;
 }