From 70edb4bd431f6b1ca52753dfbba7ecfd9eb06dd8 Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Mon, 13 Mar 2023 21:03:15 +0800 Subject: [PATCH 1/3] rename: MasaCallerOptionsExtensions -> MasaCallerClientExtensions --- ...nsExtensions.cs => MasaCallerClientExtensions.cs} | 12 ++++++------ ...nsExtensions.cs => MasaCallerClientExtensions.cs} | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) rename src/BuildingBlocks/Service/Masa.BuildingBlocks.Service.Caller/Extensions/{MasaCallerOptionsExtensions.cs => MasaCallerClientExtensions.cs} (65%) rename src/Contrib/Service/Caller/Serialization/Masa.Contrib.Service.Caller.Serialization.Xml/Extensions/{MasaCallerOptionsExtensions.cs => MasaCallerClientExtensions.cs} (67%) diff --git a/src/BuildingBlocks/Service/Masa.BuildingBlocks.Service.Caller/Extensions/MasaCallerOptionsExtensions.cs b/src/BuildingBlocks/Service/Masa.BuildingBlocks.Service.Caller/Extensions/MasaCallerClientExtensions.cs similarity index 65% rename from src/BuildingBlocks/Service/Masa.BuildingBlocks.Service.Caller/Extensions/MasaCallerOptionsExtensions.cs rename to src/BuildingBlocks/Service/Masa.BuildingBlocks.Service.Caller/Extensions/MasaCallerClientExtensions.cs index 7863d7702..6ed079ee6 100644 --- a/src/BuildingBlocks/Service/Masa.BuildingBlocks.Service.Caller/Extensions/MasaCallerOptionsExtensions.cs +++ b/src/BuildingBlocks/Service/Masa.BuildingBlocks.Service.Caller/Extensions/MasaCallerClientExtensions.cs @@ -5,22 +5,22 @@ namespace Masa.BuildingBlocks.Service.Caller; -public static class MasaCallerOptionsExtensions +public static class MasaCallerClientExtensions { /// /// Set the request handler and response handler for the specified Caller /// - /// + /// /// /// - public static MasaCallerClient UseJson(this MasaCallerClient masaCallerOptions, JsonSerializerOptions? jsonSerializerOptions) + public static MasaCallerClient UseJson(this MasaCallerClient masaCallerClient, JsonSerializerOptions? jsonSerializerOptions) { - masaCallerOptions.RequestMessageFactory = _ => new JsonRequestMessage(jsonSerializerOptions); - masaCallerOptions.ResponseMessageFactory = serviceProvider => + masaCallerClient.RequestMessageFactory = _ => new JsonRequestMessage(jsonSerializerOptions); + masaCallerClient.ResponseMessageFactory = serviceProvider => { var loggerFactory = serviceProvider.GetService(); return new JsonResponseMessage(jsonSerializerOptions, loggerFactory); }; - return masaCallerOptions; + return masaCallerClient; } } diff --git a/src/Contrib/Service/Caller/Serialization/Masa.Contrib.Service.Caller.Serialization.Xml/Extensions/MasaCallerOptionsExtensions.cs b/src/Contrib/Service/Caller/Serialization/Masa.Contrib.Service.Caller.Serialization.Xml/Extensions/MasaCallerClientExtensions.cs similarity index 67% rename from src/Contrib/Service/Caller/Serialization/Masa.Contrib.Service.Caller.Serialization.Xml/Extensions/MasaCallerOptionsExtensions.cs rename to src/Contrib/Service/Caller/Serialization/Masa.Contrib.Service.Caller.Serialization.Xml/Extensions/MasaCallerClientExtensions.cs index b1cdf4af7..3b1e877bb 100644 --- a/src/Contrib/Service/Caller/Serialization/Masa.Contrib.Service.Caller.Serialization.Xml/Extensions/MasaCallerOptionsExtensions.cs +++ b/src/Contrib/Service/Caller/Serialization/Masa.Contrib.Service.Caller.Serialization.Xml/Extensions/MasaCallerClientExtensions.cs @@ -5,21 +5,21 @@ namespace Masa.BuildingBlocks.Service.Caller; -public static class MasaCallerOptionsExtensions +public static class MasaCallerClientExtensions { /// /// Set the request handler and response handler for the specified Caller /// - /// + /// /// - public static MasaCallerClient UseXml(this MasaCallerClient masaCallerOptions) + public static MasaCallerClient UseXml(this MasaCallerClient masaCallerClient) { - masaCallerOptions.RequestMessageFactory = _ => new XmlRequestMessage(); - masaCallerOptions.ResponseMessageFactory = serviceProvider => + masaCallerClient.RequestMessageFactory = _ => new XmlRequestMessage(); + masaCallerClient.ResponseMessageFactory = serviceProvider => { var loggerFactory = serviceProvider.GetService(); return new XmlResponseMessage(loggerFactory); }; - return masaCallerOptions; + return masaCallerClient; } } From 947ace4062e5d36c2ee116bcecd4fa70d1b64d7b Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Mon, 13 Mar 2023 21:12:15 +0800 Subject: [PATCH 2/3] chore: Delete Readme, see https://docs.masastack.com/framework/building-blocks/caller/overview for details --- .../README.md | 95 ------------------ .../README.zh-CN.md | 95 ------------------ .../README.md | 98 ------------------- .../README.zh-CN.md | 98 ------------------- 4 files changed, 386 deletions(-) delete mode 100644 src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.md delete mode 100644 src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.zh-CN.md delete mode 100644 src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.md delete mode 100644 src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.zh-CN.md diff --git a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.md b/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.md deleted file mode 100644 index 6b5961467..000000000 --- a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.md +++ /dev/null @@ -1,95 +0,0 @@ -[中](README.zh-CN.md) | EN - -## Masa.Contrib.Service.Caller.DaprClient - -Provides `Dapr` based service calls - -Example: - -``` powershell -Install-Package Masa.Contrib.Service.Caller.DaprClient -``` - -### Get Started - -1. Modify `Program.cs` - -``` C# -builder.Services.AddCaller(options => -{ - options.UseDapr("UserCaller", clientBuilder => - { - clientBuilder.AppId = "" ;//AppID of the callee dapr - }); -}); -``` - -2. How to use: - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller userCaller, string name) - => userCaller.GetAsync($"/Hello", new { Name = name })); -``` - -> The interface address of the complete request is: http://localhost:3500/v1.0/invoke//method/Hello?Name={name} - -3. When there are multiple DaprClients, modify `Program.cs` - -``` C# -builder.Services.AddCaller(options => -{ - options.UseDapr("UserCaller", clientBuilder => - { - clientBuilder.AppId = "" ;//AppID of the callee User service Dapr - }); - options.UseDapr("OrderCaller", clientBuilder => - { - clientBuilder.AppId = "" ;//AppID of the callee Order service Dapr - }); -}); -``` - -4. How to use UserCaller or OrderCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller userCaller, string name) - => userCaller.GetAsync($"/Hello", new { Name = name })); - -app.MapGet("/Test/Order/Hello", ([FromServices] ICallerFactory callerFactory, string name) => -{ - var caller = callerFactory.CreateClient("OrderCaller"); - return caller.GetAsync($"/Hello", new { Name = name }); -}); -``` - -> When multiple Callers are added, how to get the specified Caller? ->> Get the Caller of the specified alias through the `CreateClient` method of `CallerFactory` -> -> Why doesn't `userCaller` get the corresponding Caller through the `CreateClient` method of `CallerFactory`? ->> If no default ICaller is specified, the default Caller is the first one added in the `AddCaller` method - -### Recommend - -1. Register `Caller`, automatically register `Caller` according to the convention, modify `Program.cs` - -``` C# -builder.Services.AddCaller(); -``` - -2. Add a new class `UserCaller`, and configure the `AppId` of the callee - -``` C# -public class UserCaller: DaprCallerBase -{ - protected override string AppId { get; set; } = ""; - - public Task HelloAsync(string name) => Caller.GetStringAsync($"/Hello", new { Name = name }); -} -``` - -3. How to use UserCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] UserCaller caller, string name) - => caller.HelloAsync(name)); -``` \ No newline at end of file diff --git a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.zh-CN.md b/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.zh-CN.md deleted file mode 100644 index 70002d0c7..000000000 --- a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/README.zh-CN.md +++ /dev/null @@ -1,95 +0,0 @@ -中 | [EN](README.md) - -## Masa.Contrib.Service.Caller.DaprClient - -提供基于`Dapr`的服务调用 - -用例: - -```c# -Install-Package Masa.Contrib.Service.Caller.DaprClient -``` - -### 入门 - -1. 注册`Caller`,并手动注册`DaprCaller`,修改`Program.cs` - -``` C# -builder.Services.AddCaller(options => -{ - options.UseDapr("UserCaller", clientBuilder => - { - clientBuilder.AppId = "" ;//被调用方dapr的AppID - }); -}); -``` - -2. 如何使用: - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller userCaller, string name) - => userCaller.GetAsync($"/Hello", new { Name = name })); -``` - -> 完整请求的接口地址是:http://localhost:3500/v1.0/invoke//method/Hello?Name={name} - -3. 当存在多个DaprClient时,则修改`Program.cs`为 - -``` C# -builder.Services.AddCaller(options => -{ - options.UseDapr("UserCaller", clientBuilder => - { - clientBuilder.AppId = "" ;//被调用方User服务Dapr的AppID - }); - options.UseDapr("OrderCaller", clientBuilder => - { - clientBuilder.AppId = "" ;//被调用方Order服务Dapr的AppID - }); -}); -``` - -4. 如何使用UserCaller或OrderCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller userCaller, string name) - => userCaller.GetAsync($"/Hello", new { Name = name })); - -app.MapGet("/Test/Order/Hello", ([FromServices] ICallerFactory callerFactory, string name) => -{ - var caller = callerFactory.CreateClient("OrderCaller"); - return caller.GetAsync($"/Hello", new { Name = name }); -}); -``` - -> 当多个Caller被添加时,如何获取指定的Caller? ->> 通过`CallerFactory`的`CreateClient`方法得到指定别名的Caller -> -> 为什么`userCaller`没有通过`CallerFactory`的`CreateClient`方法得到对应的Caller? ->> 如果未指定默认的ICaller,则在`AddCaller`方法中第一个被添加的就是默认的Caller - -### 推荐 - -1. 注册`Caller`,根据约定自动注册`Caller`,修改`Program.cs` - -``` C# -builder.Services.AddCaller(); -``` - -2. 新增加类`UserCaller`, 并配置被调用方的`AppId` - -``` C# -public class UserCaller: DaprCallerBase -{ - protected override string AppId { get; set; } = ""; - - public Task HelloAsync(string name) => Caller.GetStringAsync($"/Hello", new { Name = name }); -} -``` - -3. 如何使用UserCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] UserCaller caller, string name) - => caller.HelloAsync(name)); -``` \ No newline at end of file diff --git a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.md b/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.md deleted file mode 100644 index cc2e1f7d1..000000000 --- a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.md +++ /dev/null @@ -1,98 +0,0 @@ -[中](README.zh-CN.md) | EN - -## Masa.Contrib.Service.Caller.HttpClient - -Provide service calls based on `HttpClient`, and the subsequent migration to `Dapr`-based service calls costs less - -Example: - -``` powershell -Install-Package Masa.Contrib.Service.Caller.HttpClient -``` - -### Get Started - -1. Register `Caller`, modify `Program.cs` - -``` C# -builder.Services.AddCaller("UserCaller", options => -{ - options.UseHttpClient(client => client.BaseAddress = "http://localhost:5000"); -}); -``` - -2. How to use: - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller caller, string name) - => caller.GetAsync($"/Hello", new { Name = name })); -``` - -> The interface address of the complete request is: http://localhost:5000/Hello?Name={name} - -3. When there are multiple HttpClients, modify `Program.cs` - -``` C# -builder.Services.AddCaller("UserCaller", options => -{ - options.UseHttpClient(client => client.BaseAddress = "http://localhost:5000"); -}); -builder.Services.AddCaller("OrderCaller", options => -{ - options.UseHttpClient("OrderCaller", client => client.BaseAddress = "http://localhost:6000"); -}); -``` - -4. How to use UserCaller or OrderCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller caller, string name) - => caller.GetAsync($"/Hello", new { Name = name }));// Get UserCaller - -app.MapGet("/Test/Order/Hello", ([FromServices] ICallerFactory callerFactory, string name) => -{ - var caller = callerFactory.Create("OrderCaller"); - return caller.GetAsync($"/Hello", new { Name = name }); -}); -``` - -> When multiple Callers are added, how to get the specified Caller? ->> Get the Caller of the specified alias through the `Create` method of `CallerFactory` -> -> Why doesn't `caller` get the corresponding Caller through the `Create` method of `CallerFactory`? ->> If no default ICaller is specified, the default Caller is the first one added in the `AddCaller` method - -### Recommend - -1. Register `Caller`, automatically register `Caller` according to the convention, modify `Program.cs` - -``` C# -builder.Services.AddCaller(); -``` - -2. Add a new class `UserCaller`, and inherit `HttpClientCallerBase`, configure the domain address - -``` C# -public class UserCaller: HttpClientCallerBase -{ - protected override string BaseAddress { get; set; } = "http://localhost:5000"; - - public Task HelloAsync(string name) => Caller.GetStringAsync($"/Hello", new { Name = name }); - - /// - /// There is no need to overload by default, and it can be overloaded when there are special requirements for httpClient - /// - /// - protected override void ConfigureHttpClient(System.Net.Http.HttpClient httpClient) - { - httpClient.Timeout = TimeSpan.FromSeconds(5); - } -} -``` - -3. How to use UserCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] UserCaller caller, string name) - => caller.HelloAsync(name)); -``` \ No newline at end of file diff --git a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.zh-CN.md b/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.zh-CN.md deleted file mode 100644 index 7ab0149d2..000000000 --- a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.HttpClient/README.zh-CN.md +++ /dev/null @@ -1,98 +0,0 @@ -中 | [EN](README.md) - -## Masa.Contrib.Service.Caller.HttpClient - -提供基于`HttpClient`的服务调用,后续迁移到基于`Dapr`的服务调用成本更低 - -用例: - -``` powershell -Install-Package Masa.Contrib.Service.Caller.HttpClient -``` - -### 入门 - -1. 注册`Caller`,并手动注册`HttpCaller`,修改`Program.cs` - -``` C# -builder.Services.AddCaller("UserCaller", options => -{ - options.UseHttpClient(client => client.BaseAddress = "http://localhost:5000"); -}); -``` - -2. 如何使用: - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller caller, string name) - => caller.GetAsync($"/Hello", new { Name = name })); -``` - -> 完整请求的接口地址是:http://localhost:5000/Hello?Name={name} - -3. 当存在多个HttpClient时,则修改`Program.cs`为 - -``` C# -builder.Services.AddCaller("UserCaller", options => -{ - options.UseHttpClient(client => client.BaseAddress = "http://localhost:5000"); -}); -builder.Services.AddCaller("OrderCaller", options => -{ - options.UseHttpClient("OrderCaller", client => client.BaseAddress = "http://localhost:6000"); -}); -``` - -4. 如何使用UserCaller或OrderCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] ICaller caller, string name) - => caller.GetAsync($"/Hello", new { Name = name })); // 获取到的是UserCaller - -app.MapGet("/Test/Order/Hello", ([FromServices] ICallerFactory callerFactory, string name) => -{ - var orderCaller = callerFactory.Create("OrderCaller"); - return orderCaller.GetAsync($"/Hello", new { Name = name }); -}); -``` - -> 当多个Caller被添加时,如何获取指定的Caller? ->> 通过`CallerFactory`的`Create`方法得到指定别名的Caller -> -> 为什么`caller`没有通过`CallerFactory`的`Create`方法得到对应的Caller? ->> 如果未指定默认的ICallerProvider,则在`AddCaller`方法中第一个被添加的就是默认的Caller - -### 推荐 - -1. 注册`Caller`,根据约定自动注册`Caller`,修改`Program.cs` - -``` C# -builder.Services.AddCaller(); -``` - -2. 新增加类`UserCaller`,并继承`HttpClientCallerBase`,配置域地址 - -``` C# -public class UserCaller: HttpClientCallerBase -{ - protected override string BaseAddress { get; set; } = "http://localhost:5000"; - - public Task HelloAsync(string name) => Caller.GetStringAsync($"/Hello", new { Name = name }); - - /// - /// 默认不需要重载,对httpClient有特殊需求时可重载 - /// - /// - protected override void ConfigureHttpClient(System.Net.Http.HttpClient httpClient) - { - httpClient.Timeout = TimeSpan.FromSeconds(5); - } -} -``` - -3. 如何使用UserCaller - -``` C# -app.MapGet("/Test/User/Hello", ([FromServices] UserCaller caller, string name) - => caller.HelloAsync(name)); -``` \ No newline at end of file From 09bd3d57acfbfcc97784d31e32a62a884434a2fb Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Tue, 14 Mar 2023 10:20:50 +0800 Subject: [PATCH 3/3] chore: Modify Expired Description --- .../Masa.BuildingBlocks.Globalization.I18n/CultureSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildingBlocks/Globalization/Masa.BuildingBlocks.Globalization.I18n/CultureSettings.cs b/src/BuildingBlocks/Globalization/Masa.BuildingBlocks.Globalization.I18n/CultureSettings.cs index 800cf910b..b38405189 100644 --- a/src/BuildingBlocks/Globalization/Masa.BuildingBlocks.Globalization.I18n/CultureSettings.cs +++ b/src/BuildingBlocks/Globalization/Masa.BuildingBlocks.Globalization.I18n/CultureSettings.cs @@ -8,7 +8,7 @@ public class CultureSettings public string? ResourcesDirectory { get; set; } #pragma warning disable S1133 - [Obsolete($"${nameof(SupportCultureName)} has expired, please use ${nameof(SupportCultureFileName)} instead")] + [Obsolete($"{nameof(SupportCultureName)} has expired, please use {nameof(SupportCultureFileName)} instead")] public string? SupportCultureName { get; set; } #pragma warning restore S1133