Update Dapr document.

pull/14164/head
maliming 3 years ago
parent d7204df550
commit a09dbf1318
No known key found for this signature in database
GPG Key ID: 096224957E51C89E

@ -62,6 +62,27 @@ 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.
@ -249,18 +270,15 @@ In addition to ABP's standard distributed event bus system, you can also use Dap
````csharp
public class MyService : ITransientDependency
{
private readonly IAbpDaprClientFactory _daprClientFactory;
private readonly DaprClient _daprClient;
public MyService(IAbpDaprClientFactory daprClientFactory)
public MyService(DaprClient daprClient)
{
_daprClientFactory = daprClientFactory;
_daprClient = daprClient;
}
public async Task DoItAsync()
{
// Create a DaprClient object with default options
DaprClient _daprClient = await _daprClientFactory.CreateAsync();
await _daprClient.PublishEventAsync(
"pubsub", // pubsub name
"StockChanged", // topic name

@ -62,6 +62,27 @@ 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`,因此你可以配置设置.
@ -249,19 +270,16 @@ public class MyHandler :
````csharp
public class MyService : ITransientDependency
{
private readonly IAbpDaprClientFactory _daprClientFactory;
private readonly DaprClient _daprClient;
public MyService(IAbpDaprClientFactory daprClientFactory)
public MyService(DaprClient daprClient)
{
_daprClientFactory = daprClientFactory;
_daprClient = daprClient;
}
public async Task DoItAsync()
{
// Create a DaprClient object with default options
DaprClient daprClient = await _daprClientFactory.CreateAsync();
await daprClient.PublishEventAsync(
await _daprClient.PublishEventAsync(
"pubsub", // pubsub name
"StockChanged", // topic name
new StockCountChangedEto // event data

Loading…
Cancel
Save