diff --git a/aspnet-core/LINGYUN.MicroService.Common.sln b/aspnet-core/LINGYUN.MicroService.Common.sln index 3b38a85c6..dd0d4c426 100644 --- a/aspnet-core/LINGYUN.MicroService.Common.sln +++ b/aspnet-core/LINGYUN.MicroService.Common.sln @@ -154,6 +154,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Rules.RulesEngi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Rules.NRules.Tests", "tests\LINGYUN.Abp.Rules.NRules.Tests\LINGYUN.Abp.Rules.NRules.Tests.csproj", "{EF03A0A7-A93E-4DEF-A33E-F5A82E995FBF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Dapr.Client.Tests", "tests\LINGYUN.Abp.Dapr.Client.Tests\LINGYUN.Abp.Dapr.Client.Tests.csproj", "{9403FC1F-9677-489F-A03A-0B456153EE86}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Dapr.Tests", "tests\LINGYUN.Abp.Dapr.Tests\LINGYUN.Abp.Dapr.Tests.csproj", "{26E87199-F0AD-4B30-B0E4-080B12E6F8FC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Dapr.AspNetCore.TestHost", "tests\LINGYUN.Abp.Dapr.AspNetCore.TestHost\LINGYUN.Abp.Dapr.AspNetCore.TestHost.csproj", "{8968EDAF-9F5C-4786-AF2A-D3928B70C3EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -400,6 +406,18 @@ Global {EF03A0A7-A93E-4DEF-A33E-F5A82E995FBF}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF03A0A7-A93E-4DEF-A33E-F5A82E995FBF}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF03A0A7-A93E-4DEF-A33E-F5A82E995FBF}.Release|Any CPU.Build.0 = Release|Any CPU + {9403FC1F-9677-489F-A03A-0B456153EE86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9403FC1F-9677-489F-A03A-0B456153EE86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9403FC1F-9677-489F-A03A-0B456153EE86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9403FC1F-9677-489F-A03A-0B456153EE86}.Release|Any CPU.Build.0 = Release|Any CPU + {26E87199-F0AD-4B30-B0E4-080B12E6F8FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26E87199-F0AD-4B30-B0E4-080B12E6F8FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26E87199-F0AD-4B30-B0E4-080B12E6F8FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26E87199-F0AD-4B30-B0E4-080B12E6F8FC}.Release|Any CPU.Build.0 = Release|Any CPU + {8968EDAF-9F5C-4786-AF2A-D3928B70C3EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8968EDAF-9F5C-4786-AF2A-D3928B70C3EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8968EDAF-9F5C-4786-AF2A-D3928B70C3EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8968EDAF-9F5C-4786-AF2A-D3928B70C3EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -477,6 +495,9 @@ Global {E861BE01-689D-4637-A5DC-E78E234F83FB} = {C8891F1A-E6E5-448A-B527-EBFA44D20808} {CF253F0A-3A45-40EE-875F-0E57C8968C48} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {EF03A0A7-A93E-4DEF-A33E-F5A82E995FBF} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} + {9403FC1F-9677-489F-A03A-0B456153EE86} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} + {26E87199-F0AD-4B30-B0E4-080B12E6F8FC} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} + {8968EDAF-9F5C-4786-AF2A-D3928B70C3EC} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DaprClientBuilderExtensions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DaprClientBuilderExtensions.cs new file mode 100644 index 000000000..fef9d9732 --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DaprClientBuilderExtensions.cs @@ -0,0 +1,72 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using System; + +namespace Dapr.Client +{ + public static class DaprClientBuilderExtensions + { + public static IDaprClientBuilder ConfigureDaprClient(this IDaprClientBuilder builder, Action configureClient) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (configureClient == null) + { + throw new ArgumentNullException(nameof(configureClient)); + } + + builder.Services.Configure(builder.Name, options => + { + options.DaprClientActions.Add(configureClient); + }); + + return builder; + } + + public static IDaprClientBuilder ConfigureDaprClient(this IDaprClientBuilder builder, Action configureBuilder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (configureBuilder == null) + { + throw new ArgumentNullException(nameof(configureBuilder)); + } + + builder.Services.Configure(builder.Name, options => + { + options.DaprClientBuilderActions.Add(configureBuilder); + }); + + return builder; + } + + public static IDaprClientBuilder ConfigureDaprClient(this IDaprClientBuilder builder, Action configureClientBuilder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (configureClientBuilder == null) + { + throw new ArgumentNullException(nameof(configureClientBuilder)); + } + + builder.Services.AddTransient>(services => + { + return new ConfigureNamedOptions(builder.Name, (options) => + { + options.DaprClientBuilderActions.Add(client => configureClientBuilder(services, client)); + }); + }); + + return builder; + } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DaprClientFactoryOptions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DaprClientFactoryOptions.cs new file mode 100644 index 000000000..6a379ab74 --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DaprClientFactoryOptions.cs @@ -0,0 +1,21 @@ +using Grpc.Net.Client; +using System; +using System.Collections.Generic; +using System.Text.Json; + +namespace Dapr.Client +{ + public class DaprClientFactoryOptions + { + public string DaprApiToken{ get; set; } + public string HttpEndpoint { get; set; } + public string GrpcEndpoint { get; set; } + public GrpcChannelOptions GrpcChannelOptions { get; set; } + public JsonSerializerOptions JsonSerializerOptions { get; set; } + public IList> DaprClientActions { get; } = new List>(); + public IList> DaprClientBuilderActions { get; } = new List>(); + public DaprClientFactoryOptions() + { + } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DefaultDaprClientBuilder.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DefaultDaprClientBuilder.cs new file mode 100644 index 000000000..6a8a5da8d --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DefaultDaprClientBuilder.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace Dapr.Client +{ + internal class DefaultDaprClientBuilder : IDaprClientBuilder + { + public DefaultDaprClientBuilder(IServiceCollection services, string name) + { + Services = services; + Name = name; + } + + public string Name { get; } + + public IServiceCollection Services { get; } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DefaultDaprClientFactory.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DefaultDaprClientFactory.cs new file mode 100644 index 000000000..909008e70 --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/DefaultDaprClientFactory.cs @@ -0,0 +1,82 @@ +using Microsoft.Extensions.Options; +using System; +using System.Collections.Concurrent; +using System.Threading; + +namespace Dapr.Client +{ + public class DefaultDaprClientFactory : IDaprClientFactory + { + private readonly IOptionsMonitor _optionsMonitor; + + private readonly Func> _daprClientFactory; + internal readonly ConcurrentDictionary> _daprClients; + + public DefaultDaprClientFactory( + IOptionsMonitor optionsMonitor) + { + _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); + + _daprClients = new ConcurrentDictionary>(); + + _daprClientFactory = (name) => + { + return new Lazy(() => + { + return InternalCreateDaprClient(name); + }, LazyThreadSafetyMode.ExecutionAndPublication); + }; + } + + public DaprClient CreateClient(string name) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + var client = _daprClients.GetOrAdd(name, _daprClientFactory).Value; + + var options = _optionsMonitor.Get(name); + for (int i = 0; i < options.DaprClientActions.Count; i++) + { + options.DaprClientActions[i](client); + } + + return client; + } + + internal DaprClient InternalCreateDaprClient(string name) + { + var builder = new DaprClientBuilder(); + + var options = _optionsMonitor.Get(name); + + if (!string.IsNullOrWhiteSpace(options.HttpEndpoint)) + { + builder.UseHttpEndpoint(options.HttpEndpoint); + } + if (!string.IsNullOrWhiteSpace(options.GrpcEndpoint)) + { + builder.UseGrpcEndpoint(options.GrpcEndpoint); + } + if (options.GrpcChannelOptions != null) + { + builder.UseGrpcChannelOptions(options.GrpcChannelOptions); + } + if (options.JsonSerializerOptions != null) + { + builder.UseJsonSerializationOptions(options.JsonSerializerOptions); + } + + builder.UseDaprApiToken(options.DaprApiToken); + + for (int i = 0; i < options.DaprClientBuilderActions.Count; i++) + { + options.DaprClientBuilderActions[i](builder); + } + + return builder.Build(); + } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/IDaprClientBuilder.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/IDaprClientBuilder.cs new file mode 100644 index 000000000..1e4122f0c --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/IDaprClientBuilder.cs @@ -0,0 +1,10 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace Dapr.Client +{ + public interface IDaprClientBuilder + { + string Name { get; } + IServiceCollection Services { get; } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/IDaprClientFactory.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/IDaprClientFactory.cs new file mode 100644 index 000000000..66bc3d13f --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Dapr/Client/IDaprClientFactory.cs @@ -0,0 +1,7 @@ +namespace Dapr.Client +{ + public interface IDaprClientFactory + { + DaprClient CreateClient(string name); + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientBuilderOptions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientBuilderOptions.cs new file mode 100644 index 000000000..4a02e419f --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientBuilderOptions.cs @@ -0,0 +1,22 @@ +using Dapr.Client; +using System; +using System.Collections.Generic; + +namespace LINGYUN.Abp.Dapr.Client +{ + public class AbpDaprClientBuilderOptions + { + public List> ProxyClientActions { get; } + + public List> ProxyClientBuildActions { get; } + + internal HashSet ConfiguredProxyClients { get; } + + public AbpDaprClientBuilderOptions() + { + ConfiguredProxyClients = new HashSet(); + ProxyClientActions = new List>(); + ProxyClientBuildActions = new List>(); + } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs index 89b05d2fc..1caf070ac 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Volo.Abp.Http.Client; using Volo.Abp.Modularity; @@ -17,10 +18,7 @@ namespace LINGYUN.Abp.Dapr.Client { var configuration = context.Services.GetConfiguration(); Configure(configuration); - Configure(configuration.GetSection("Dapr:Client")); - - // DaprClient应该配置为单例的实现 - context.Services.AddDaprClient(); + context.Services.AddHttpClient(DaprHttpClient); } } } diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientOptions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientOptions.cs deleted file mode 100644 index e61cdb01e..000000000 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientOptions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Grpc.Net.Client; - -namespace LINGYUN.Abp.Dapr.Client -{ - public class AbpDaprClientOptions - { - public string GrpcEndpoint { get; set; } - public string HttpEndpoint { get; set; } - public GrpcChannelOptions GrpcChannelOptions { get; set; } - public AbpDaprClientOptions() - { - } - } -} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprApiDescriptionFinder.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprApiDescriptionFinder.cs index d58be33dd..a3422dd0f 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprApiDescriptionFinder.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprApiDescriptionFinder.cs @@ -27,15 +27,15 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying protected ICorrelationIdProvider CorrelationIdProvider { get; } protected ICurrentTenant CurrentTenant { get; } - protected DaprClient DaprClient { get; } + protected IDaprClientFactory DaprClientFactory { get; } public DaprApiDescriptionFinder( - DaprClient daprClient, + IDaprClientFactory daprClientFactory, IApiDescriptionCache cache, IOptions abpCorrelationIdOptions, ICorrelationIdProvider correlationIdProvider, ICurrentTenant currentTenant) { - DaprClient = daprClient; + DaprClientFactory = daprClientFactory; Cache = cache; AbpCorrelationIdOptions = abpCorrelationIdOptions.Value; @@ -44,9 +44,9 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying CancellationTokenProvider = NullCancellationTokenProvider.Instance; } - public virtual async Task FindActionAsync(string appId, Type serviceType, MethodInfo method) + public virtual async Task FindActionAsync(string service, string appId, Type serviceType, MethodInfo method) { - var apiDescription = await GetApiDescriptionAsync(appId); + var apiDescription = await GetApiDescriptionAsync(service, appId); //TODO: Cache finding? @@ -88,18 +88,19 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying throw new AbpException($"Could not found remote action for method: {method} on the appId: {appId}"); } - public virtual async Task GetApiDescriptionAsync(string appId) + public virtual async Task GetApiDescriptionAsync(string service, string appId) { - return await Cache.GetAsync(appId, () => GetApiDescriptionFromServerAsync(appId)); + return await Cache.GetAsync(appId, () => GetApiDescriptionFromServerAsync(service, appId)); } - protected virtual async Task GetApiDescriptionFromServerAsync(string appId) + protected virtual async Task GetApiDescriptionFromServerAsync(string service, string appId) { - var requestMessage = DaprClient.CreateInvokeMethodRequest(HttpMethod.Get, appId, "api/abp/api-definition"); + var client = DaprClientFactory.CreateClient(service); + var requestMessage = client.CreateInvokeMethodRequest(HttpMethod.Get, appId, "api/abp/api-definition"); AddHeaders(requestMessage); - var response = await DaprClient.InvokeMethodWithResponseAsync( + var response = await client.InvokeMethodWithResponseAsync( requestMessage, CancellationTokenProvider.Token); diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprClientProxy.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprClientProxy.cs new file mode 100644 index 000000000..23a380bfb --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprClientProxy.cs @@ -0,0 +1,12 @@ +namespace LINGYUN.Abp.Dapr.Client.DynamicProxying +{ + public class DaprClientProxy : IDaprClientProxy + { + public TRemoteService Service { get; } + + public DaprClientProxy(TRemoteService service) + { + Service = service; + } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs index d1401450a..5f2b3f18f 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs @@ -32,7 +32,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying { protected static MethodInfo MakeRequestAndGetResultAsyncMethod { get; } - protected DaprClient DaprClient { get; } + protected IDaprClientFactory DaprClientFactory { get; } protected ICancellationTokenProvider CancellationTokenProvider { get; } protected ICorrelationIdProvider CorrelationIdProvider { get; } protected ICurrentTenant CurrentTenant { get; } @@ -54,7 +54,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying } public DynamicDaprClientProxyInterceptor( - DaprClient daprClient, + IDaprClientFactory daprClientFactory, IOptions clientProxyOptions, IOptionsSnapshot remoteServiceOptions, IDaprApiDescriptionFinder apiDescriptionFinder, @@ -66,7 +66,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying IOptions correlationIdOptions, ICurrentTenant currentTenant) { - DaprClient = daprClient; + DaprClientFactory = daprClientFactory; CancellationTokenProvider = cancellationTokenProvider; CorrelationIdProvider = correlationIdProvider; CurrentTenant = currentTenant; @@ -145,6 +145,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying // 遵循远端 api/abp/api-definition var action = await ApiDescriptionFinder.FindActionAsync( + clientConfig.RemoteServiceName, remoteServiceConfig.AppId, typeof(TService), invocation.Method @@ -156,7 +157,8 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying // 需要合并端点作为dapr远程调用的方法名称 var methodName = UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion); - var requestMessage = DaprClient.CreateInvokeMethodRequest( + var daprClient = DaprClientFactory.CreateClient(clientConfig.RemoteServiceName); + var requestMessage = daprClient.CreateInvokeMethodRequest( action.GetHttpMethod(), remoteServiceConfig.AppId, methodName); @@ -165,23 +167,25 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying AddHeaders(invocation, action, requestMessage, apiVersion); - var client = HttpClientFactory.Create(AbpDaprClientModule.DaprHttpClient); + var httpClient = HttpClientFactory.Create(AbpDaprClientModule.DaprHttpClient); await ClientAuthenticator.Authenticate( new RemoteServiceHttpClientAuthenticateContext( - client, + httpClient, requestMessage, - remoteServiceConfig, + new RemoteServiceConfiguration( + remoteServiceConfig.BaseUrl, + remoteServiceConfig.Version), clientConfig.RemoteServiceName ) ); // 其他库可能将授权标头写入到HttpClient中 if (requestMessage.Headers.Authorization == null && - client.DefaultRequestHeaders.Authorization != null) + httpClient.DefaultRequestHeaders.Authorization != null) { - requestMessage.Headers.Authorization = client.DefaultRequestHeaders.Authorization; + requestMessage.Headers.Authorization = httpClient.DefaultRequestHeaders.Authorization; } - var response = await DaprClient.InvokeMethodWithResponseAsync(requestMessage, GetCancellationToken()); + var response = await daprClient.InvokeMethodWithResponseAsync(requestMessage, GetCancellationToken()); if (!response.IsSuccessStatusCode) { diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/IDaprApiDescriptionFinder.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/IDaprApiDescriptionFinder.cs index fd4998d7f..f99067250 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/IDaprApiDescriptionFinder.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/IDaprApiDescriptionFinder.cs @@ -7,8 +7,8 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying { public interface IDaprApiDescriptionFinder { - Task FindActionAsync(string appId, Type serviceType, MethodInfo invocationMethod); + Task FindActionAsync(string service, string appId, Type serviceType, MethodInfo invocationMethod); - Task GetApiDescriptionAsync(string appId); + Task GetApiDescriptionAsync(string service, string appId); } } diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/IDaprClientProxy.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/IDaprClientProxy.cs new file mode 100644 index 000000000..9686f3fad --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/IDaprClientProxy.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.Dapr.Client.DynamicProxying +{ + public interface IDaprClientProxy + { + TRemoteService Service { get; } + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprClientProxyExtensions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprClientProxyExtensions.cs index a6d8e610b..bde7e72ff 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprClientProxyExtensions.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprClientProxyExtensions.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Reflection; using Volo.Abp; using Volo.Abp.Castle.DynamicProxy; -using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Validation; namespace Microsoft.Extensions.DependencyInjection @@ -19,39 +18,97 @@ namespace Microsoft.Extensions.DependencyInjection { private static readonly ProxyGenerator ProxyGeneratorInstance = new ProxyGenerator(); + #region Add DaprClient Builder + public static IServiceCollection AddDaprClient( + [NotNull] this IServiceCollection services) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + + services.AddLogging(); + services.AddOptions(); + + services.TryAddSingleton(); + services.TryAddSingleton(serviceProvider => serviceProvider.GetRequiredService()); + + return services; + } + + public static IDaprClientBuilder AddDaprClient( [NotNull] this IServiceCollection services, - Action setup = null) + string name) { - Check.NotNull(services, nameof(services)); + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + + services.AddDaprClient(); - services.TryAddSingleton(provider => + return new DefaultDaprClientBuilder(services, name); + } + + public static IDaprClientBuilder AddDaprClient( + [NotNull] this IServiceCollection services, + string name, + Action configureClient) + { + if (services == null) { - var abpSystemTextJsonSerializerOptions = provider.GetRequiredService>().Value; - var abpDaprClientOptions = provider.GetRequiredService>().Value; + throw new ArgumentNullException(nameof(services)); + } - var builder = new DaprClientBuilder() - .UseHttpEndpoint(abpDaprClientOptions.HttpEndpoint) - .UseJsonSerializationOptions(abpSystemTextJsonSerializerOptions.JsonSerializerOptions); + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } - if (!abpDaprClientOptions.GrpcEndpoint.IsNullOrWhiteSpace() && - abpDaprClientOptions.GrpcChannelOptions != null) - { - builder - .UseGrpcEndpoint(abpDaprClientOptions.GrpcEndpoint) - .UseGrpcChannelOptions(abpDaprClientOptions.GrpcChannelOptions); - } + if (configureClient == null) + { + throw new ArgumentNullException(nameof(configureClient)); + } - setup?.Invoke(builder); + services.AddDaprClient(); - return builder.Build(); - }); + var builder = new DefaultDaprClientBuilder(services, name); + builder.ConfigureDaprClient(configureClient); + return builder; + } - services.AddHttpClient(AbpDaprClientModule.DaprHttpClient); + public static IDaprClientBuilder AddDaprClient( + [NotNull] this IServiceCollection services, + string name, + Action configureClient) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } - return services; + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + if (configureClient == null) + { + throw new ArgumentNullException(nameof(configureClient)); + } + + services.AddDaprClient(); + var builder = new DefaultDaprClientBuilder(services, name); + builder.ConfigureDaprClient(configureClient); + return builder; } + + #endregion + + #region Add DaprClient Proxies + public static IServiceCollection AddDaprClientProxies( [NotNull] this IServiceCollection services, [NotNull] Assembly assembly, @@ -96,7 +153,7 @@ namespace Microsoft.Extensions.DependencyInjection Check.NotNull(type, nameof(type)); Check.NotNullOrWhiteSpace(remoteServiceConfigurationName, nameof(remoteServiceConfigurationName)); - // AddHttpClientFactory(services, remoteServiceConfigurationName); + services.AddDaprClientFactory(remoteServiceConfigurationName); services.Configure(options => { @@ -124,6 +181,64 @@ namespace Microsoft.Extensions.DependencyInjection ); } + services.AddTransient( + typeof(IDaprClientProxy<>).MakeGenericType(type), + serviceProvider => + { + var service = ProxyGeneratorInstance + .CreateInterfaceProxyWithoutTarget( + type, + (IInterceptor)serviceProvider.GetRequiredService(validationInterceptorAdapterType), + (IInterceptor)serviceProvider.GetRequiredService(interceptorAdapterType) + ); + + return Activator.CreateInstance( + typeof(DaprClientProxy<>).MakeGenericType(type), + service + ); + }); + + return services; + } + + private static IServiceCollection AddDaprClientFactory( + [NotNull] this IServiceCollection services, + [NotNull] string remoteServiceConfigurationName = DaprRemoteServiceConfigurationDictionary.DefaultName) + { + var preOptions = services.ExecutePreConfiguredActions(); + + if (preOptions.ConfiguredProxyClients.Contains(remoteServiceConfigurationName)) + { + return services; + } + + var clientBuilder = services.AddDaprClient(remoteServiceConfigurationName, (IServiceProvider provider, DaprClientBuilder builder) => + { + var options = provider.GetRequiredService>().Value; + builder.UseHttpEndpoint( + options.RemoteServices + .GetConfigurationOrDefault(remoteServiceConfigurationName).BaseUrl); + + foreach (var clientBuildAction in preOptions.ProxyClientBuildActions) + { + clientBuildAction(remoteServiceConfigurationName, provider, builder); + } + }); + + clientBuilder.ConfigureDaprClient((client) => + { + foreach (var clientBuildAction in preOptions.ProxyClientActions) + { + clientBuildAction(remoteServiceConfigurationName, client); + } + }); + + + services.PreConfigure(options => + { + options.ConfiguredProxyClients.Add(remoteServiceConfigurationName); + }); + return services; } @@ -136,5 +251,7 @@ namespace Microsoft.Extensions.DependencyInjection && !type.IsGenericType && typeof(IRemoteService).IsAssignableFrom(type); } + + #endregion } } diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/README.md b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/README.md index cd0b4a156..804f8fbe2 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/README.md +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/README.md @@ -100,14 +100,10 @@ dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run ```json { - "Dapr": { - "Client": { - "HttpEndpoint": "http://127.0.0.1:50000" - } - }, "RemoteServices": { "System": { - "AppId": "myapp" + "AppId": "myapp", + "BaseUrl": "http://127.0.0.1:50000" } } } @@ -155,24 +151,16 @@ public class InvokeClass ## 配置项说明 - -* AbpDaprClientOptions.GrpcEndpoint Dapr暴露的Grpc端点, 对应 **DaprClientBuilder.GrpcEndpoint** -* AbpDaprClientOptions.HttpEndpoint Dapr暴露的Http端点, 对应 **DaprClientBuilder.HttpEndpoint** -* AbpDaprClientOptions.GrpcChannelOptions 通过Grpc调用远程服务的配置项, 对应 **DaprClientBuilder.GrpcChannelOptions** * AbpDaprRemoteServiceOptions.RemoteServices 配置Dapr.AppId ```json { - "Dapr": { - "Client": { - "HttpEndpoint": "http://127.0.0.1:50000" - } - }, "RemoteServices": { "System": { - "AppId": "myapp" + "AppId": "myapp", + "BaserUrl": ""http://127.0.0.1:50000"" } } } diff --git a/aspnet-core/modules/dapr/README.md b/aspnet-core/modules/dapr/README.md index 5b5f56f5a..c46f805a4 100644 --- a/aspnet-core/modules/dapr/README.md +++ b/aspnet-core/modules/dapr/README.md @@ -75,14 +75,10 @@ dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run ```json { - "Dapr": { - "Client": { - "HttpEndpoint": "http://127.0.0.1:50000" - } - }, "RemoteActors": { "System": { - "ActorId": "1" + "ActorId": "1", + "BaseUrl": "http://127.0.0.1:50000" } } } diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN.Abp.Dapr.AspNetCore.TestHost.csproj b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN.Abp.Dapr.AspNetCore.TestHost.csproj new file mode 100644 index 000000000..c24fd328f --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN.Abp.Dapr.AspNetCore.TestHost.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + + + + + + + + + + + + + + diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/AbpDaprAspNetCoreTestHostModule.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/AbpDaprAspNetCoreTestHostModule.cs new file mode 100644 index 000000000..1d888b099 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/AbpDaprAspNetCoreTestHostModule.cs @@ -0,0 +1,39 @@ +using LINGYUN.Abp.Dapr.Actors.AspNetCore; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Dapr +{ + [DependsOn( + typeof(AbpAspNetCoreMvcModule), + typeof(AbpDaprActorsAspNetCoreModule) + )] + public class AbpDaprAspNetCoreTestHostModule : AbpModule + { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + Configure(builder => + { + builder.AddApplicationPart(typeof(AbpDaprAspNetCoreTestHostModule).Assembly); + }); + } + + public override void ConfigureServices(ServiceConfigurationContext context) + { + var hostingEnvironment = context.Services.GetHostingEnvironment(); + var configuration = context.Services.GetConfiguration(); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var app = context.GetApplicationBuilder(); + + app.UseRouting(); + app.UseAuditing(); + app.UseConfiguredEndpoints(); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/Actors/TestActor.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/Actors/TestActor.cs new file mode 100644 index 000000000..bfbedf609 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/Actors/TestActor.cs @@ -0,0 +1,61 @@ +using Dapr.Actors.Runtime; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.Dapr.Actors +{ + public class TestActor : Actor, ITestActor, ISingletonDependency + { + public TestActor(ActorHost host) : base(host) + { + } + + public async Task> GetAsync() + { + var values = await GetValuesByStateAsync(); + + return new ListResultDto(values); + } + + public async Task UpdateAsync() + { + var values = await GetValuesByStateAsync(); + + var inctement = await StateManager.AddOrUpdateStateAsync( + "test:actors:increment", + 1, + (key, value) => + { + return value + 1; + }); + + values[0].Value = $"value:updated:{inctement}"; + + return values[0]; + } + + public async Task ClearAsync() + { + await StateManager.TryRemoveStateAsync("test:actors:increment"); + await StateManager.TryRemoveStateAsync("test:actors"); + } + + protected virtual async Task> GetValuesByStateAsync() + { + return await StateManager + .GetOrAddStateAsync( + "test:actors", + new List + { + new NameValue("name1", "value1"), + new NameValue("name2", "value2"), + new NameValue("name3", "value3"), + new NameValue("name4", "value4"), + new NameValue("name5", "value5") + }); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/ServiceInvocation/TestAppService.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/ServiceInvocation/TestAppService.cs new file mode 100644 index 000000000..355ef0a37 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/ServiceInvocation/TestAppService.cs @@ -0,0 +1,41 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace LINGYUN.Abp.Dapr.ServiceInvocation +{ + [RemoteService(Name = "TestDapr")] + [Route("api/dapr/test")] + public class TestAppService : AbpController, ITestAppService + { + private static int _inctement; + private readonly List _cache = new List + { + new NameValue("name1", "value1"), + new NameValue("name2", "value2"), + new NameValue("name3", "value3"), + new NameValue("name4", "value4"), + new NameValue("name5", "value5") + }; + + [HttpGet] + public Task> GetAsync() + { + return Task.FromResult(new ListResultDto(_cache)); + } + + [HttpPut] + public Task UpdateAsync() + { + Interlocked.Increment(ref _inctement); + + _cache[0].Value = $"value:updated:{_inctement}"; + + return Task.FromResult(_cache[0]); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Program.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Program.cs new file mode 100644 index 000000000..7ef748e9d --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Program.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace LINGYUN.Abp.Dapr.AspNetCore.TestHost +{ + public class Program + { + public static int Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + + return 0; + } + + internal static IHostBuilder CreateHostBuilder(string[] args) => + Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) + .UseAutofac(); + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Properties/launchSettings.json b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Properties/launchSettings.json new file mode 100644 index 000000000..40df8fddb --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Properties/launchSettings.json @@ -0,0 +1,21 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:29703", + "sslPort": 0 + } + }, + "profiles": { + "LINGYUN.Abp.Dapr.AspNetCore.TestHost": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": false, + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Startup.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Startup.cs new file mode 100644 index 000000000..33c1d4037 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/Startup.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace LINGYUN.Abp.Dapr.AspNetCore.TestHost +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddApplication(); + } + + public void Configure(IApplicationBuilder app) + { + app.InitializeApplication(); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN.Abp.Dapr.Client.Tests.csproj b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN.Abp.Dapr.Client.Tests.csproj new file mode 100644 index 000000000..5a1e75b05 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN.Abp.Dapr.Client.Tests.csproj @@ -0,0 +1,34 @@ + + + + net5.0 + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + PreserveNewest + + + + diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/AbpDaptClientTestBase.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/AbpDaptClientTestBase.cs new file mode 100644 index 000000000..e21774530 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/AbpDaptClientTestBase.cs @@ -0,0 +1,34 @@ +using LINGYUN.Abp.Tests; +using Microsoft.Extensions.DependencyInjection; +using System.Diagnostics; +using System.IO; +using System.Threading; + +namespace LINGYUN.Abp.Dapr.Client.Tests +{ + public class AbpDaptClientTestBase : AbpTestsBase + { + // private Process _hostProcess; + + //protected override void BeforeAddApplication(IServiceCollection services) + //{ + // // TODO: 运行测试前先启动宿主进程 dapr run --app-id testdapr --app-port 5000 -H 10000 -- dotnet run --no-build + // var workingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "../../../../LINGYUN.Abp.Dapr.AspNetCore.TestHost"); + // _hostProcess = Process.Start(new ProcessStartInfo + // { + // WorkingDirectory = workingDirectory, + // FileName = "powershell", + // Arguments = "dapr run --app-id testdapr --app-port 5000 -H 10000 -- dotnet run --no-build", + // UseShellExecute = true + // }); + + // // 等待.NET进程启动完毕 + // Thread.Sleep(15000); + //} + + //public override void Dispose() + //{ + // _hostProcess?.CloseMainWindow(); + //} + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/AbpDaptClientTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/AbpDaptClientTestModule.cs new file mode 100644 index 000000000..e9d617160 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/AbpDaptClientTestModule.cs @@ -0,0 +1,33 @@ +using LINGYUN.Abp.Tests; +using Volo.Abp.Modularity; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; +using System.IO; + +namespace LINGYUN.Abp.Dapr.Client.Tests +{ + [DependsOn( + typeof(AbpDaprTestModule), + typeof(AbpTestsBaseModule), + typeof(AbpDaprClientModule))] + public class AbpDaptClientTestModule : AbpModule + { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + context.Services.ReplaceConfiguration( + ConfigurationHelper.BuildConfiguration( + new AbpConfigurationBuilderOptions + { + EnvironmentName = "Development", + BasePath = Directory.GetCurrentDirectory() + })); + } + + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddDaprClientProxies( + typeof(AbpDaprTestModule).Assembly, + "TestDapr"); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/TestAppServiceTests.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/TestAppServiceTests.cs new file mode 100644 index 000000000..26520b04f --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/TestAppServiceTests.cs @@ -0,0 +1,33 @@ +using LINGYUN.Abp.Dapr.ServiceInvocation; +using Shouldly; +using System.Threading.Tasks; +using Xunit; + +namespace LINGYUN.Abp.Dapr.Client.Tests +{ + public class TestAppServiceTests : AbpDaptClientTestBase + { + private readonly ITestAppService _service; + + public TestAppServiceTests() + { + _service = GetRequiredService(); + } + + [Fact] + public async Task Get_Result_Items_Count_Should_5() + { + var result = await _service.GetAsync(); + + result.Items.Count.ShouldBe(5); + } + + [Fact] + public async Task Update_Result_Value_Should_Value_Updated_1() + { + var result = await _service.UpdateAsync(); + + result.Value.ShouldBe("value:updated:1"); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN.Abp.Dapr.Tests.csproj b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN.Abp.Dapr.Tests.csproj new file mode 100644 index 000000000..60045d91b --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN.Abp.Dapr.Tests.csproj @@ -0,0 +1,13 @@ + + + + net5.0 + + false + + + + + + + diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/AbpDaprTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/AbpDaprTestModule.cs new file mode 100644 index 000000000..6fa217477 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/AbpDaprTestModule.cs @@ -0,0 +1,11 @@ +using Volo.Abp.Application; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Dapr +{ + [DependsOn( + typeof(AbpDddApplicationContractsModule))] + public class AbpDaprTestModule : AbpModule + { + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/Actors/ITestActor.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/Actors/ITestActor.cs new file mode 100644 index 000000000..87960d107 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/Actors/ITestActor.cs @@ -0,0 +1,17 @@ +using Dapr.Actors; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.Dapr.Actors +{ + [RemoteService(Name = "Test")] + public interface ITestActor : IActor + { + Task> GetAsync(); + + Task UpdateAsync(); + + Task ClearAsync(); + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/ServiceInvocation/ITestAppService.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/ServiceInvocation/ITestAppService.cs new file mode 100644 index 000000000..8f779a866 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/ServiceInvocation/ITestAppService.cs @@ -0,0 +1,14 @@ +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.Dapr.ServiceInvocation +{ + public interface ITestAppService : IApplicationService + { + Task> GetAsync(); + + Task UpdateAsync(); + } +}