Browse Source

Merge pull request #245 from colinin/4.2

update dapr README.MD
pull/252/head
cKey 5 years ago
committed by GitHub
parent
commit
27065c3e1f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 135
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/README.md
  2. 4
      aspnet-core/modules/dapr/README.md

135
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/README.md

@ -1,3 +1,5 @@
[Actors](../README.md) | Dapr.Actors 文档
# LINGYUN.Abp.Dapr.Client # LINGYUN.Abp.Dapr.Client
实现了Dapr文档中的服务间调用,项目设计与Volo.Abp.Http.Client一致,通过配置文件即可无缝替代Volo.Abp.Http.Client 实现了Dapr文档中的服务间调用,项目设计与Volo.Abp.Http.Client一致,通过配置文件即可无缝替代Volo.Abp.Http.Client
@ -16,12 +18,143 @@ public class YouProjectModule : AbpModule
{ {
// 注册代理类似于 Volo.Abp.Http.Client 模块 // 注册代理类似于 Volo.Abp.Http.Client 模块
context.Services.AddDaprClientProxies( context.Services.AddDaprClientProxies(
typeof(YouProjectActorInterfaceModule).Assembly, // 搜索 YouProjectActorInterfaceModule 模块下的远程服务定义 typeof(YouProjectInterfaceModule).Assembly, // 搜索 YouProjectInterfaceModule 模块下的远程服务定义
RemoteServiceName
);
}
}
```
### 1、接口定义
```c#
// IApplicationService 实现了 IRemoteService
public interface ISystemAppService : IApplicationService
{
Task<string> GetAsync();
}
public class SystemInterfaceModule : AbpModule
{
}
```
### 2、服务端
引用 Volo.Abp.AspNetCore.Mvc
* 实现接口
```c#
public class SystemAppService : ApplicationService, ISystemAppService
{
public Task<string> GetAsync()
{
retuen Task.FromResult("System");
}
}
```
* 创建模块
```c#
// 模块会自动搜索实现了IActor的服务,注册为Dapr的Actors
[DependsOn(
typeof(SystemInterfaceModule),
typeof(AbpAspNetCoreMvcModule))]
public class SystemServerModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<IMvcBuilder>(mvcBuilder =>
{
mvcBuilder.AddApplicationPartIfNotExists(typeof(SystemInterfaceModule).Assembly);
});
}
}
```
* 发布到Dapr
```shell
# --app-port .net程序映射端口
# -H 对外暴露 http 监听端口
# -G 对外暴露 grpc 监听端口
dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run
```
### 3、客户端
引用 LINGYUN.Abp.Dapr.Client
* 配置文件 **appsettings.json**
```json
{
"Dapr": {
"Client": {
"HttpEndpoint": "http://127.0.0.1:50000"
}
},
"RemoteServices": {
"System": {
"AppId": "myapp"
}
}
}
```
* 客户端代码
```c#
// 模块依赖
[DependsOn(
typeof(AbpDaprClientModule))]
public class SystemActorClientModule : AbpModule
{
private const string RemoteServiceName = "System";
public override void ConfigureServices(ServiceConfigurationContext context)
{
// 注册代理类似于 Volo.Abp.Http.Client 模块
context.Services.AddDaprClientProxies(
typeof(SystemInterfaceModule).Assembly, // 搜索 SystemActorInterfaceModule 模块下的IActor定义
RemoteServiceName RemoteServiceName
); );
} }
} }
// 调用方法,直接依赖注入即可
public class InvokeClass
{
private readonly ISystemAppService _systemAppService;
public InvokeClass(ISystemAppService systemAppService)
{
_systemAppService = systemAppService;
}
public async Task InvokeAsync()
{
await _systemAppService.GetAsync();
}
}
``` ```
## 配置项说明 ## 配置项说明
* AbpDaprClientOptions.GrpcEndpoint Dapr暴露的Grpc端点, 对应 **DaprClientBuilder.GrpcEndpoint** * AbpDaprClientOptions.GrpcEndpoint Dapr暴露的Grpc端点, 对应 **DaprClientBuilder.GrpcEndpoint**

4
aspnet-core/modules/dapr/README.md

@ -1,3 +1,5 @@
[Client](./LINGYUN.Abp.Dapr.Client/README.md) | Dapr.Client 文档
# Dapr.Actors 集成 # Dapr.Actors 集成
## 配置使用 ## 配置使用
@ -30,7 +32,7 @@ public class SystemActorInterfaceModule : AbpModule
```c# ```c#
public class SystemActor : Actor public class SystemActor : Actor, ISystemActor
{ {
public Task<string> GetAsync() public Task<string> GetAsync()
{ {

Loading…
Cancel
Save