Skip to content
old lee edited this page Feb 1, 2019 · 1 revision

Image text

依赖

  1. 使用Microsoft.Extensions.Dependency Injection自动组装和构建相关的组件类型。
  2. 流序列化使用 protobuf-net
  3. 动态代理生成使用 Roslyn
  4. 通信管道和服务宿主使用 DotNetty

简单使用

在你的Web Api Core中添加如下代码,实现中间件扩展服务注入。

app.UseConsulServerExtensions(Configuration,
    collection =>
    {
        collection.AddSingleton<IProxyService, ProxyImpl>();
    },
    typeof(AuthorizationServerProvider)
);

在你的应用程序中,添加如下代码,即可实现客户端代理生成。

using (var proxy = ClientProxy.Generate<IProxyService>(new Uri("http://127.0.0.1:8500")))
{
    Console.WriteLine($@"{proxy.Sync(1)}");
    Console.WriteLine($@"{proxy.Async(1).Result}");
    Console.WriteLine($@"{proxy.GetDictionaryAsync().Result["key"]}");
}

具体接口及接口实现由你自行定义,以上只是一个最简单的框架调用示例。

Clone this wiki locally