grpc/csharp-dotnet/api/Microsoft.Extensions.Depend...

625 lines
29 KiB
HTML

<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Class GrpcClientServiceExtensions
| gRPC for .NET </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="Class GrpcClientServiceExtensions
| gRPC for .NET ">
<meta name="generator" content="docfx 2.36.0.0">
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" href="../styles/docfx.vendor.css">
<link rel="stylesheet" href="../styles/docfx.css">
<link rel="stylesheet" href="../styles/main.css">
<meta property="docfx:navrel" content="../toc.html">
<meta property="docfx:tocrel" content="toc.html">
<meta property="docfx:rel" content="../">
</head>
<body data-spy="scroll" data-target="#affix" data-offset="120">
<div id="wrapper">
<header>
<nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html">
<img id="logo" class="svg" src="../logo.svg" alt="">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<form class="navbar-form navbar-right" role="search" id="search">
<div class="form-group">
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
</div>
</form>
</div>
</div>
</nav>
<div class="subnav navbar navbar-default">
<div class="container hide-when-search" id="breadcrumb">
<ul class="breadcrumb">
<li></li>
</ul>
</div>
</div>
</header>
<div class="container body-content">
<div id="search-results">
<div class="search-list"></div>
<div class="sr-items">
<p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
</div>
<ul id="pagination"></ul>
</div>
</div>
<div role="main" class="container body-content hide-when-search">
<div class="sidenav hide-when-search">
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
<div class="sidetoggle collapse" id="sidetoggle">
<div id="sidetoc"></div>
</div>
</div>
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions">
<h1 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions" class="text-break">Class GrpcClientServiceExtensions
</h1>
<div class="markdown level0 summary"><p>Extensions methods to configure an <see cref="!:IServiceCollection"></see> for <see cref="!:IHttpClientFactory"></see> with gRPC.</p>
</div>
<div class="markdown level0 conceptual"></div>
<div class="inheritance">
<h5>Inheritance</h5>
<div class="level0"><span class="xref">System.Object</span></div>
<div class="level1"><span class="xref">GrpcClientServiceExtensions</span></div>
</div>
<h6><strong>Namespace</strong>: <a class="xref" href="Microsoft.Extensions.DependencyInjection.html">Microsoft.Extensions.DependencyInjection</a></h6>
<h6><strong>Assembly</strong>: Grpc.Net.ClientFactory.dll</h6>
<h5 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_syntax">Syntax</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static class GrpcClientServiceExtensions : object</code></pre>
</div>
<h3 id="methods">Methods
</h3>
<a id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient*"></a>
<h4 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient``1(IServiceCollection)">AddGrpcClient&lt;TClient&gt;(IServiceCollection)</h4>
<div class="markdown level1 summary"><p>Adds the <see cref="!:IHttpClientFactory"></see> and related services to the <see cref="!:IServiceCollection"></see> and configures
a binding between the <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> type and a named <see cref="!:HttpClient"></see>. The client name
will be set to the type name of <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static IHttpClientBuilder AddGrpcClient&lt;TClient&gt;(this IServiceCollection services)
where TClient : ClientBase</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IServiceCollection</span></td>
<td><span class="parametername">services</span></td>
<td><p>The <see cref="!:IServiceCollection"></see>.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IHttpClientBuilder</span></td>
<td><p>An <see cref="!:IHttpClientBuilder"></see> that can be used to configure the client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="parametername">TClient</span></td>
<td><p>The type of the gRPC client. The type specified will be registered in the service collection as
a transient service.</p>
</td>
</tr>
</tbody>
</table>
<h5 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>
<see cref="!:HttpClient"></see> instances that apply the provided configuration can be retrieved using
<see cref="!:IHttpClientFactory.CreateClient(string)"></see> and providing the matching name.
</p>
<p>
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> instances constructed with the appropriate <see cref="!:HttpClient"></see>
can be retrieved from <see cref="!:IServiceProvider.GetService(Type)"></see> (and related methods) by providing
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> as the service type.
</p>
</div>
<a id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient*"></a>
<h4 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_Action_Grpc_Net_ClientFactory_GrpcClientFactoryOptions__" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient``1(IServiceCollection,Action{Grpc.Net.ClientFactory.GrpcClientFactoryOptions})">AddGrpcClient&lt;TClient&gt;(IServiceCollection, Action&lt;GrpcClientFactoryOptions&gt;)</h4>
<div class="markdown level1 summary"><p>Adds the <see cref="!:IHttpClientFactory"></see> and related services to the <see cref="!:IServiceCollection"></see> and configures
a binding between the <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> type and a named <see cref="!:HttpClient"></see>. The client name
will be set to the type name of <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static IHttpClientBuilder AddGrpcClient&lt;TClient&gt;(this IServiceCollection services, Action&lt;GrpcClientFactoryOptions&gt; configureClient)
where TClient : ClientBase</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IServiceCollection</span></td>
<td><span class="parametername">services</span></td>
<td><p>The <see cref="!:IServiceCollection"></see>.</p>
</td>
</tr>
<tr>
<td><span class="xref">Action</span>&lt;<a class="xref" href="Grpc.Net.ClientFactory.GrpcClientFactoryOptions.html">GrpcClientFactoryOptions</a>&gt;</td>
<td><span class="parametername">configureClient</span></td>
<td><p>A delegate that is used to configure the gRPC client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IHttpClientBuilder</span></td>
<td><p>An <see cref="!:IHttpClientBuilder"></see> that can be used to configure the client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="parametername">TClient</span></td>
<td><p>The type of the gRPC client. The type specified will be registered in the service collection as
a transient service.</p>
</td>
</tr>
</tbody>
</table>
<h5 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_Action_Grpc_Net_ClientFactory_GrpcClientFactoryOptions___remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>
<see cref="!:HttpClient"></see> instances that apply the provided configuration can be retrieved using
<see cref="!:IHttpClientFactory.CreateClient(string)"></see> and providing the matching name.
</p>
<p>
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> instances constructed with the appropriate <see cref="!:HttpClient"></see>
can be retrieved from <see cref="!:IServiceProvider.GetService(Type)"></see> (and related methods) by providing
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> as the service type.
</p>
</div>
<a id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient*"></a>
<h4 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_Action_IServiceProvider_Grpc_Net_ClientFactory_GrpcClientFactoryOptions__" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient``1(IServiceCollection,Action{IServiceProvider,Grpc.Net.ClientFactory.GrpcClientFactoryOptions})">AddGrpcClient&lt;TClient&gt;(IServiceCollection, Action&lt;IServiceProvider, GrpcClientFactoryOptions&gt;)</h4>
<div class="markdown level1 summary"><p>Adds the <see cref="!:IHttpClientFactory"></see> and related services to the <see cref="!:IServiceCollection"></see> and configures
a binding between the <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> type and a named <see cref="!:HttpClient"></see>. The client name
will be set to the type name of <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static IHttpClientBuilder AddGrpcClient&lt;TClient&gt;(this IServiceCollection services, Action&lt;IServiceProvider, GrpcClientFactoryOptions&gt; configureClient)
where TClient : ClientBase</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IServiceCollection</span></td>
<td><span class="parametername">services</span></td>
<td><p>The <see cref="!:IServiceCollection"></see>.</p>
</td>
</tr>
<tr>
<td><span class="xref">Action</span>&lt;<span class="xref">IServiceProvider</span>, <a class="xref" href="Grpc.Net.ClientFactory.GrpcClientFactoryOptions.html">GrpcClientFactoryOptions</a>&gt;</td>
<td><span class="parametername">configureClient</span></td>
<td><p>A delegate that is used to configure the gRPC client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IHttpClientBuilder</span></td>
<td><p>An <see cref="!:IHttpClientBuilder"></see> that can be used to configure the client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="parametername">TClient</span></td>
<td><p>The type of the gRPC client. The type specified will be registered in the service collection as
a transient service.</p>
</td>
</tr>
</tbody>
</table>
<h5 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_Action_IServiceProvider_Grpc_Net_ClientFactory_GrpcClientFactoryOptions___remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>
<see cref="!:HttpClient"></see> instances that apply the provided configuration can be retrieved using
<see cref="!:IHttpClientFactory.CreateClient(string)"></see> and providing the matching name.
</p>
<p>
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> instances constructed with the appropriate <see cref="!:HttpClient"></see>
can be retrieved from <see cref="!:IServiceProvider.GetService(Type)"></see> (and related methods) by providing
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> as the service type.
</p>
<p>
The <see cref="!:IServiceProvider"></see> argument provided to <code data-dev-comment-type="paramref" class="paramref">configureClient</code> will be
a reference to a scoped service provider that shares the lifetime of the handler being constructed.
</p>
</div>
<a id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient*"></a>
<h4 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_System_String_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient``1(IServiceCollection,System.String)">AddGrpcClient&lt;TClient&gt;(IServiceCollection, String)</h4>
<div class="markdown level1 summary"><p>Adds the <see cref="!:IHttpClientFactory"></see> and related services to the <see cref="!:IServiceCollection"></see> and configures
a binding between the <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> type and a named <see cref="!:HttpClient"></see>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static IHttpClientBuilder AddGrpcClient&lt;TClient&gt;(this IServiceCollection services, string name)
where TClient : ClientBase</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IServiceCollection</span></td>
<td><span class="parametername">services</span></td>
<td><p>The <see cref="!:IServiceCollection"></see>.</p>
</td>
</tr>
<tr>
<td><span class="xref">System.String</span></td>
<td><span class="parametername">name</span></td>
<td><p>The logical name of the <see cref="!:HttpClient"></see> to configure.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IHttpClientBuilder</span></td>
<td><p>An <see cref="!:IHttpClientBuilder"></see> that can be used to configure the client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="parametername">TClient</span></td>
<td><p>The type of the gRPC client. The type specified will be registered in the service collection as
a transient service.</p>
</td>
</tr>
</tbody>
</table>
<h5 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_System_String__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>
<see cref="!:HttpClient"></see> instances that apply the provided configuration can be retrieved using
<see cref="!:IHttpClientFactory.CreateClient(string)"></see> and providing the matching name.
</p>
<p>
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> instances constructed with the appropriate <see cref="!:HttpClient"></see>
can be retrieved from <see cref="!:IServiceProvider.GetService(Type)"></see> (and related methods) by providing
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> as the service type.
</p>
</div>
<a id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient*"></a>
<h4 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_System_String_Action_Grpc_Net_ClientFactory_GrpcClientFactoryOptions__" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient``1(IServiceCollection,System.String,Action{Grpc.Net.ClientFactory.GrpcClientFactoryOptions})">AddGrpcClient&lt;TClient&gt;(IServiceCollection, String, Action&lt;GrpcClientFactoryOptions&gt;)</h4>
<div class="markdown level1 summary"><p>Adds the <see cref="!:IHttpClientFactory"></see> and related services to the <see cref="!:IServiceCollection"></see> and configures
a binding between the <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> type and a named <see cref="!:HttpClient"></see>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static IHttpClientBuilder AddGrpcClient&lt;TClient&gt;(this IServiceCollection services, string name, Action&lt;GrpcClientFactoryOptions&gt; configureClient)
where TClient : ClientBase</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IServiceCollection</span></td>
<td><span class="parametername">services</span></td>
<td><p>The <see cref="!:IServiceCollection"></see>.</p>
</td>
</tr>
<tr>
<td><span class="xref">System.String</span></td>
<td><span class="parametername">name</span></td>
<td><p>The logical name of the <see cref="!:HttpClient"></see> to configure.</p>
</td>
</tr>
<tr>
<td><span class="xref">Action</span>&lt;<a class="xref" href="Grpc.Net.ClientFactory.GrpcClientFactoryOptions.html">GrpcClientFactoryOptions</a>&gt;</td>
<td><span class="parametername">configureClient</span></td>
<td><p>A delegate that is used to configure the gRPC client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IHttpClientBuilder</span></td>
<td><p>An <see cref="!:IHttpClientBuilder"></see> that can be used to configure the client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="parametername">TClient</span></td>
<td><p>The type of the gRPC client. The type specified will be registered in the service collection as
a transient service.</p>
</td>
</tr>
</tbody>
</table>
<h5 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_System_String_Action_Grpc_Net_ClientFactory_GrpcClientFactoryOptions___remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>
<see cref="!:HttpClient"></see> instances that apply the provided configuration can be retrieved using
<see cref="!:IHttpClientFactory.CreateClient(string)"></see> and providing the matching name.
</p>
<p>
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> instances constructed with the appropriate <see cref="!:HttpClient"></see>
can be retrieved from <see cref="!:IServiceProvider.GetService(Type)"></see> (and related methods) by providing
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> as the service type.
</p>
</div>
<a id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient_" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient*"></a>
<h4 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_System_String_Action_IServiceProvider_Grpc_Net_ClientFactory_GrpcClientFactoryOptions__" data-uid="Microsoft.Extensions.DependencyInjection.GrpcClientServiceExtensions.AddGrpcClient``1(IServiceCollection,System.String,Action{IServiceProvider,Grpc.Net.ClientFactory.GrpcClientFactoryOptions})">AddGrpcClient&lt;TClient&gt;(IServiceCollection, String, Action&lt;IServiceProvider, GrpcClientFactoryOptions&gt;)</h4>
<div class="markdown level1 summary"><p>Adds the <see cref="!:IHttpClientFactory"></see> and related services to the <see cref="!:IServiceCollection"></see> and configures
a binding between the <code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> type and a named <see cref="!:HttpClient"></see>.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public static IHttpClientBuilder AddGrpcClient&lt;TClient&gt;(this IServiceCollection services, string name, Action&lt;IServiceProvider, GrpcClientFactoryOptions&gt; configureClient)
where TClient : ClientBase</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IServiceCollection</span></td>
<td><span class="parametername">services</span></td>
<td><p>The <see cref="!:IServiceCollection"></see>.</p>
</td>
</tr>
<tr>
<td><span class="xref">System.String</span></td>
<td><span class="parametername">name</span></td>
<td><p>The logical name of the <see cref="!:HttpClient"></see> to configure.</p>
</td>
</tr>
<tr>
<td><span class="xref">Action</span>&lt;<span class="xref">IServiceProvider</span>, <a class="xref" href="Grpc.Net.ClientFactory.GrpcClientFactoryOptions.html">GrpcClientFactoryOptions</a>&gt;</td>
<td><span class="parametername">configureClient</span></td>
<td><p>A delegate that is used to configure the gRPC client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">IHttpClientBuilder</span></td>
<td><p>An <see cref="!:IHttpClientBuilder"></see> that can be used to configure the client.</p>
</td>
</tr>
</tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="parametername">TClient</span></td>
<td><p>The type of the gRPC client. The type specified will be registered in the service collection as
a transient service.</p>
</td>
</tr>
</tbody>
</table>
<h5 id="Microsoft_Extensions_DependencyInjection_GrpcClientServiceExtensions_AddGrpcClient__1_IServiceCollection_System_String_Action_IServiceProvider_Grpc_Net_ClientFactory_GrpcClientFactoryOptions___remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>
<see cref="!:HttpClient"></see> instances that apply the provided configuration can be retrieved using
<see cref="!:IHttpClientFactory.CreateClient(string)"></see> and providing the matching name.
</p>
<p>
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> instances constructed with the appropriate <see cref="!:HttpClient"></see>
can be retrieved from <see cref="!:IServiceProvider.GetService(Type)"></see> (and related methods) by providing
<code data-dev-comment-type="typeparamref" class="typeparamref">TClient</code> as the service type.
</p>
<p>
The <see cref="!:IServiceProvider"></see> argument provided to <code data-dev-comment-type="paramref" class="paramref">configureClient</code> will be
a reference to a scoped service provider that shares the lifetime of the handler being constructed.
</p>
</div>
</article>
</div>
<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
<!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
</nav>
</div>
</div>
</div>
</div>
<footer>
<div class="grad-bottom"></div>
<div class="footer">
<div class="container">
<span class="pull-right">
<a href="#top">Back to top</a>
</span>
<span>Generated by <strong>DocFX</strong></span>
</div>
</div>
</footer>
</div>
<script type="text/javascript" src="../styles/docfx.vendor.js"></script>
<script type="text/javascript" src="../styles/docfx.js"></script>
<script type="text/javascript" src="../styles/main.js"></script>
</body>
</html>