コード例 #1
0
        public IGrpcHost Build()
        {
            var hostingServices        = BuildCommonServices();
            var applicationServices    = hostingServices.Clone();
            var hostingServiceProvider = GetProviderFromFactory(hostingServices);

            var host = new GrpcHost(
                applicationServices,
                hostingServiceProvider,
                _options,
                _config);

            host.Initialize();

            return(host);

            IServiceProvider GetProviderFromFactory(IServiceCollection collection)
            {
                var provider = collection.BuildServiceProvider();
                var factory  = provider.GetService <IServiceProviderFactory <IServiceCollection> >();

                if (factory != null)
                {
                    using (provider)
                    {
                        return(factory.CreateServiceProvider(factory.CreateBuilder(collection)));
                    }
                }

                return(provider);
            }
        }
コード例 #2
0
        public IGrpcHost Build()
        {
            if (_grpcHostBuilt)
            {
                throw new InvalidOperationException("GrpcHostBuilder allows creation only of a single instance of GrpcHost");
            }
            _grpcHostBuilt = true;

            var hostingServices        = BuildCommonServices();
            var applicationServices    = hostingServices.Clone();
            var hostingServiceProvider = hostingServices.BuildServiceProvider();

            var host = new GrpcHost(applicationServices, hostingServiceProvider, _config, _serviceTypes);

            host.Initialize();
            return(host);
        }