Browse Source

Update `Dapr` document.

pull/18117/head
maliming 3 years ago
parent
commit
7668ba2aa3
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 30
      docs/en/Dapr/Index.md
  2. 30
      docs/zh-Hans/Dapr/Index.md

30
docs/en/Dapr/Index.md

@ -60,29 +60,6 @@ Alternatively, you can configure the options in the `Dapr` section of your `apps
}
````
### Injecting DaprClient
ABP registers the `DaprClient` class to the [dependency injection](../Dependency-Injection.md) system. So, you can inject and use it whenever you need:
````csharp
public class MyService : ITransientDependency
{
private readonly DaprClient _daprClient;
public MyService(DaprClient daprClient)
{
_daprClient = daprClient;
}
public async Task DoItAsync()
{
// TODO: Use the injected _daprClient object
}
}
````
Injecting `DaprClient` is the recommended way of using it in your application code. When you inject it, the `IAbpDaprClientFactory` service is used to create it, which is explained in the next section.
### IAbpDaprClientFactory
`IAbpDaprClientFactory` can be used to create `DaprClient` or `HttpClient` objects to perform operations on Dapr. It uses `AbpDaprOptions`, so you can configure the settings in a central place.
@ -113,15 +90,14 @@ public class MyService : ITransientDependency
});
// Create an HttpClient object
HttpClient httpClient = await _daprClientFactory
.CreateHttpClientAsync("target-app-id");
HttpClient httpClient = await _daprClientFactory.CreateHttpClientAsync("target-app-id");
}
}
````
`CreateHttpClientAsync` method also gets optional `daprEndpoint` and `daprApiToken` parameters.
> ABP uses `IAbpDaprClientFactory` when it needs to create a Dapr client. You can also use Dapr API to create client objects in your application. Using `IAbpDaprClientFactory` is recommended, but not required.
> You can use Dapr API to create client objects in your application. Using `IAbpDaprClientFactory` is recommended, but not required.
## C# API Client Proxies Integration
@ -412,7 +388,7 @@ Or you can set it in your `appsettings.json` file:
}
````
Once you set it, it is used when you inject `DaprClient` or use `IAbpDaprClientFactory`. If you need that value in your application, you can inject `IDaprApiTokenProvider` and use its `GetDaprApiToken()` method.
Once you set it, it is used when you use `IAbpDaprClientFactory`. If you need that value in your application, you can inject `IDaprApiTokenProvider` and use its `GetDaprApiToken()` method.
### App API Token

30
docs/zh-Hans/Dapr/Index.md

@ -60,29 +60,6 @@ Configure<AbpDaprOptions>(options =>
}
````
### 注入DaprClient
ABP 将 `DaprClient` 类注册到 [依赖注入](../Dependency-Injection.md) 系统中.因此,你可以在需要时注入并使用它:
````csharp
public class MyService : ITransientDependency
{
private readonly DaprClient _daprClient;
public MyService(DaprClient daprClient)
{
_daprClient = daprClient;
}
public async Task DoItAsync()
{
// TODO: Use the injected _daprClient object
}
}
````
注入 `DaprClient` 是在应用程序代码中使用它的推荐方法.当你注入它时,将使用 `IAbpDaprClientFactory` 服务创建它,这会在下一节中将进行说明.
### IAbpDaprClientFactory
`IAbpDaprClientFactory` 可用于创建 `DaprClient``HttpClient` 对象来执行对 Dapr 的操作.它使用 `AbpDaprOptions`,因此你可以配置设置.
@ -113,15 +90,14 @@ public class MyService : ITransientDependency
});
// Create an HttpClient object
HttpClient httpClient = await _daprClientFactory
.CreateHttpClientAsync("target-app-id");
HttpClient httpClient = await _daprClientFactory.CreateHttpClientAsync("target-app-id");
}
}
````
`CreateHttpClientAsync` 方法还获取可选的 `daprEndpoint``daprApiToken` 参数.
> ABP使用`IAbpDaprClientFactory`创建Dapr客户端.可以在应用程序中使用Dapr API创建客户端对象.推荐使用`IAbpDaprClientFactory`,但不是必需的.
> 你可以在应用程序中使用Dapr API创建客户端对象.推荐使用`IAbpDaprClientFactory`,但不是必需的.
## C# API 客户端代理集成
@ -412,7 +388,7 @@ Configure<AbpDaprOptions>(options =>
}
````
一旦你设置了它,它就会在你注入`DaprClient`或使用`IAbpDaprClientFactory`时使用.如果你需要在应用程序中使用该值,你可以注入`IDaprApiTokenProvider`并使用其`GetDaprApiToken()`方法.
一旦你设置了它,它就会在使用`IAbpDaprClientFactory`时使用.如果你需要在应用程序中使用该值,你可以注入`IDaprApiTokenProvider`并使用其`GetDaprApiToken()`方法.
### App API Token

Loading…
Cancel
Save