一个设计为通用的强类型客户端。
目前只提供了Http的支持
NuGet:https://www.nuget.org/packages/Rabbit.Go.Core
[Go("http://api.com/user")][DefaultHeader("access_token","xxxxxxxxxx")][DefaultQuery("project","samples")]publicinterfaceIUserGoClient{[GoGet("/{id}")]Task<UserModel>GetAsync(longid);[GoDelete("/{id}")]TaskDeleteAsync(longid);[GoPost]Task<long>PostAsync([GoBody]PostUserModelmodel);[GoPut("/{id}")]TaskPutAsync(longid,[GoBody]PutUserModelmodel);}publicclassUserModel{[KeyName("user_name")]publicstringUserName{get;set;}[CustomFormatter(typeof(PasswordFormatter))]publicstringPassword{get;set;}publicint?Age{get;set;}[PropertyIgnore]publicboolIsAdult{get;set;}}publicclassPasswordFormatter:IKeyValueFormatter{
#region Implementation of IKeyValueFormatter
publicTaskFormatAsync(KeyValueFormatterContextcontext){varpassword=context.Model?.ToString();if(!string.IsNullOrEmpty(password))password=Encoding.UTF8.GetString(Convert.FromBase64String(password));context.Result[context.BinderModelName]=password;returnTask.CompletedTask;}
#endregion Implementation of IKeyValueFormatter
}publicclassPostUserModel:UserModel{}publicclassPutUserModel:UserModel{}varservices=newServiceCollection().AddOptions().AddLogging().AddGoClient().BuildServiceProvider();varuserGoClient=services.GetService<IUserGoClient>();varuser=awaituserGoClient.GetAsync(1);awaituserGoClient.PutAsync(1,newPutUserModel{Age=20});- 丰富的拦截器
- 全局请求拦截器和模型公约拦截器
- 良好的抽象与实现拆分,扩展非常容易
- 支持url模板
- 可扩展的请求程序(默认 HttpGoClient)
- 不只为Http而设计(针对Grpc、dubbo等其它服务提供者进行了扩展考虑)
待补充
- 在不使用DI的情况下使用
- 提供服务发现、重试、限流、断路器的支持(集成 Rabbit Cloud)
- 提供对Grpc的调用支持
- 提供对dubbo的调用支持
- QQ群:384413261 点击加入 .NET Group
- Email:majian159@live.com