From fc4c5bd3909226b2717b892a7c6c23382a8187e3 Mon Sep 17 00:00:00 2001 From: WangJunZzz <510423039@qq.com> Date: Sat, 14 Sep 2024 15:44:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9B=86=E6=88=90WebApiClientCore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aspnet-core/Directory.Build.Microsoft.targets | 2 +- aspnet-core/Directory.Build.targets | 2 ++ aspnet-core/Lion.AbpPro.sln | 7 +++++++ .../Lion.AbpPro.HttpClient.csproj | 14 +++++++++++++ .../Lion/AbpPro/HttpClient/IDemoHttpClient.cs | 20 +++++++++++++++++++ .../HttpClient/SevenHttpClientModule.cs | 15 ++++++++++++++ .../Lion/AbpPro/HttpClient/WeatherForecast.cs | 12 +++++++++++ 7 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion.AbpPro.HttpClient.csproj create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/IDemoHttpClient.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/SevenHttpClientModule.cs create mode 100644 aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/WeatherForecast.cs diff --git a/aspnet-core/Directory.Build.Microsoft.targets b/aspnet-core/Directory.Build.Microsoft.targets index 2387a578..54413dd3 100644 --- a/aspnet-core/Directory.Build.Microsoft.targets +++ b/aspnet-core/Directory.Build.Microsoft.targets @@ -2,7 +2,7 @@ - + diff --git a/aspnet-core/Directory.Build.targets b/aspnet-core/Directory.Build.targets index b6643074..59a9319c 100644 --- a/aspnet-core/Directory.Build.targets +++ b/aspnet-core/Directory.Build.targets @@ -89,5 +89,7 @@ + + \ No newline at end of file diff --git a/aspnet-core/Lion.AbpPro.sln b/aspnet-core/Lion.AbpPro.sln index c8b283a0..7607ed0a 100644 --- a/aspnet-core/Lion.AbpPro.sln +++ b/aspnet-core/Lion.AbpPro.sln @@ -260,6 +260,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.ElasticSearch.T EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.Starter", "frameworks\src\Lion.AbpPro.Starter\Lion.AbpPro.Starter.csproj", "{A70659A2-91F4-4FE7-80D0-DA12430543FD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.HttpClient", "frameworks\src\Lion.AbpPro.HttpClient\Lion.AbpPro.HttpClient.csproj", "{9C88C5AE-21A1-4A62-9FA3-173806CD9EE3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -638,6 +640,10 @@ Global {A70659A2-91F4-4FE7-80D0-DA12430543FD}.Debug|Any CPU.Build.0 = Debug|Any CPU {A70659A2-91F4-4FE7-80D0-DA12430543FD}.Release|Any CPU.ActiveCfg = Release|Any CPU {A70659A2-91F4-4FE7-80D0-DA12430543FD}.Release|Any CPU.Build.0 = Release|Any CPU + {9C88C5AE-21A1-4A62-9FA3-173806CD9EE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C88C5AE-21A1-4A62-9FA3-173806CD9EE3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C88C5AE-21A1-4A62-9FA3-173806CD9EE3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C88C5AE-21A1-4A62-9FA3-173806CD9EE3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -761,6 +767,7 @@ Global {CCC3BE80-5D36-4833-B629-9F4230396EC3} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} {2B2110E1-4C29-41AF-ADB5-C1B5F3C3C1D0} = {EFC415F8-872F-4C7E-8645-31A51481BCFC} {A70659A2-91F4-4FE7-80D0-DA12430543FD} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} + {9C88C5AE-21A1-4A62-9FA3-173806CD9EE3} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion.AbpPro.HttpClient.csproj b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion.AbpPro.HttpClient.csproj new file mode 100644 index 00000000..0ccc5d56 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion.AbpPro.HttpClient.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + Lion.AbpPro.HttpClient + + + + + + + + + diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/IDemoHttpClient.cs b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/IDemoHttpClient.cs new file mode 100644 index 00000000..6547143e --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/IDemoHttpClient.cs @@ -0,0 +1,20 @@ +using WebApiClientCore; +using WebApiClientCore.Attributes; + +namespace Lion.AbpPro.HttpClient; + +/// +/// Demo +/// +public interface IDemoHttpClient : IHttpApi +{ + /// + /// 获取天气信息 + /// + [HttpGet("api/WeatherForecast/Get")] + Task> GetAsync(CancellationToken token = default); + + + [HttpPost("api/WeatherForecast/Demo1")] + Task> PostAsync([JsonContent] WeatherForecast weatherForecasts, CancellationToken token = default); +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/SevenHttpClientModule.cs b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/SevenHttpClientModule.cs new file mode 100644 index 00000000..f2441983 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/SevenHttpClientModule.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; + +namespace Lion.AbpPro.HttpClient; + +[DependsOn(typeof(AbpAutofacModule))] +public class SevenHttpClientModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + // 示例项目 + context.Services.AddHttpApi().ConfigureHttpApi(options => { options.HttpHost = new Uri("http://localhost:5048/"); }); + } +} \ No newline at end of file diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/WeatherForecast.cs b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/WeatherForecast.cs new file mode 100644 index 00000000..104d07b2 --- /dev/null +++ b/aspnet-core/frameworks/src/Lion.AbpPro.HttpClient/Lion/AbpPro/HttpClient/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace Lion.AbpPro.HttpClient; + +public class WeatherForecast +{ + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +}