diff --git a/aspnet-core/LINGYUN.MicroService.Common.sln b/aspnet-core/LINGYUN.MicroService.Common.sln
index dd0d4c426..871b875b8 100644
--- a/aspnet-core/LINGYUN.MicroService.Common.sln
+++ b/aspnet-core/LINGYUN.MicroService.Common.sln
@@ -134,10 +134,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dapr", "dapr", "{7FDFB22F-1
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Actors", "modules\dapr\LINGYUN.Abp.Dapr.Actors\LINGYUN.Abp.Dapr.Actors.csproj", "{C72E0407-06FE-4CAA-86E5-30FF216A7B82}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Actors.IdentityModel", "modules\dapr\LINGYUN.Abp.Dapr.Actors.IdentityModel\LINGYUN.Abp.Dapr.Actors.IdentityModel.csproj", "{A5DC8C25-6504-4C35-A657-7A1BF051570F}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Actors.IdentityModel.Web", "modules\dapr\LINGYUN.Abp.Dapr.Actors.IdentityModel.Web\LINGYUN.Abp.Dapr.Actors.IdentityModel.Web.csproj", "{E263A9ED-D5DB-4495-A0C7-6268ED92EB92}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Actors.AspNetCore", "modules\dapr\LINGYUN.Abp.Dapr.Actors.AspNetCore\LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj", "{E74FF671-6E5E-430C-9211-ED910634DDBE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Client", "modules\dapr\LINGYUN.Abp.Dapr.Client\LINGYUN.Abp.Dapr.Client.csproj", "{879791A3-BD69-42E4-A3BC-9878EFAADDD1}"
@@ -154,11 +150,13 @@ 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}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Client.Tests", "tests\LINGYUN.Abp.Dapr.Client.Tests\LINGYUN.Abp.Dapr.Client.Tests.csproj", "{9403FC1F-9677-489F-A03A-0B456153EE86}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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.Tests", "tests\LINGYUN.Abp.Dapr.Tests\LINGYUN.Abp.Dapr.Tests.csproj", "{26E87199-F0AD-4B30-B0E4-080B12E6F8FC}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.AspNetCore.TestHost", "tests\LINGYUN.Abp.Dapr.AspNetCore.TestHost\LINGYUN.Abp.Dapr.AspNetCore.TestHost.csproj", "{8968EDAF-9F5C-4786-AF2A-D3928B70C3EC}"
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}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Dapr.Actors.Tests", "tests\LINGYUN.Abp.Dapr.Actors.Tests\LINGYUN.Abp.Dapr.Actors.Tests.csproj", "{CF30221B-CA7A-42CD-B91A-B7224AB2F38B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -370,14 +368,6 @@ Global
{C72E0407-06FE-4CAA-86E5-30FF216A7B82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C72E0407-06FE-4CAA-86E5-30FF216A7B82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C72E0407-06FE-4CAA-86E5-30FF216A7B82}.Release|Any CPU.Build.0 = Release|Any CPU
- {A5DC8C25-6504-4C35-A657-7A1BF051570F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A5DC8C25-6504-4C35-A657-7A1BF051570F}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A5DC8C25-6504-4C35-A657-7A1BF051570F}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A5DC8C25-6504-4C35-A657-7A1BF051570F}.Release|Any CPU.Build.0 = Release|Any CPU
- {E263A9ED-D5DB-4495-A0C7-6268ED92EB92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {E263A9ED-D5DB-4495-A0C7-6268ED92EB92}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {E263A9ED-D5DB-4495-A0C7-6268ED92EB92}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {E263A9ED-D5DB-4495-A0C7-6268ED92EB92}.Release|Any CPU.Build.0 = Release|Any CPU
{E74FF671-6E5E-430C-9211-ED910634DDBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E74FF671-6E5E-430C-9211-ED910634DDBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E74FF671-6E5E-430C-9211-ED910634DDBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -418,6 +408,10 @@ Global
{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
+ {CF30221B-CA7A-42CD-B91A-B7224AB2F38B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CF30221B-CA7A-42CD-B91A-B7224AB2F38B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CF30221B-CA7A-42CD-B91A-B7224AB2F38B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CF30221B-CA7A-42CD-B91A-B7224AB2F38B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -485,8 +479,6 @@ Global
{BA2F4EC9-BC2C-482A-9123-BDACB8B15295} = {B86C21A4-73B7-471E-B73A-B4B905EC9435}
{7FDFB22F-1BFF-4E05-9427-78B7A8461D50} = {02EA4E78-5891-43BC-944F-3E52FEE032E4}
{C72E0407-06FE-4CAA-86E5-30FF216A7B82} = {7FDFB22F-1BFF-4E05-9427-78B7A8461D50}
- {A5DC8C25-6504-4C35-A657-7A1BF051570F} = {7FDFB22F-1BFF-4E05-9427-78B7A8461D50}
- {E263A9ED-D5DB-4495-A0C7-6268ED92EB92} = {7FDFB22F-1BFF-4E05-9427-78B7A8461D50}
{E74FF671-6E5E-430C-9211-ED910634DDBE} = {7FDFB22F-1BFF-4E05-9427-78B7A8461D50}
{879791A3-BD69-42E4-A3BC-9878EFAADDD1} = {7FDFB22F-1BFF-4E05-9427-78B7A8461D50}
{C8891F1A-E6E5-448A-B527-EBFA44D20808} = {02EA4E78-5891-43BC-944F-3E52FEE032E4}
@@ -498,6 +490,7 @@ Global
{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}
+ {CF30221B-CA7A-42CD-B91A-B7224AB2F38B} = {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.Actors/LINGYUN.Abp.Dapr.Actors.csproj b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN.Abp.Dapr.Actors.csproj
index 11d5d1235..82d39ddf5 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN.Abp.Dapr.Actors.csproj
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN.Abp.Dapr.Actors.csproj
@@ -13,5 +13,6 @@
+
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorOptions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorOptions.cs
deleted file mode 100644
index eb06d987b..000000000
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorOptions.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace LINGYUN.Abp.Dapr.Actors
-{
- public class AbpDaprActorOptions
- {
- public DaprActorConfigurationDictionary RemoteActors { get; set; }
-
- public AbpDaprActorOptions()
- {
- RemoteActors = new DaprActorConfigurationDictionary();
- }
- }
-}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
index d9ae68fba..d14dc28de 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
@@ -1,24 +1,28 @@
-using Microsoft.Extensions.DependencyInjection;
-using Volo.Abp.Castle;
-using Volo.Abp.ExceptionHandling;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Volo.Abp.Http.Client;
using Volo.Abp.Modularity;
-using Volo.Abp.MultiTenancy;
-using Volo.Abp.Validation;
namespace LINGYUN.Abp.Dapr.Actors
{
[DependsOn(
- typeof(AbpCastleCoreModule),
- typeof(AbpMultiTenancyModule),
- typeof(AbpValidationModule),
- typeof(AbpExceptionHandlingModule)
+ typeof(AbpHttpClientModule)
)]
public class AbpDaprActorsModule : AbpModule
{
+ ///
+ /// 与AbpHttpClient集成,创建一个命名HttpClient
+ ///
+ internal const string DaprHttpClient = "_AbpDaprActorsClient";
+
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
- Configure(configuration);
+ Configure(options =>
+ {
+ configuration.Bind(options);
+ });
+ context.Services.AddHttpClient(DaprHttpClient);
}
}
}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprRemoteServiceOptions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprRemoteServiceOptions.cs
new file mode 100644
index 000000000..0dc9942fb
--- /dev/null
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprRemoteServiceOptions.cs
@@ -0,0 +1,14 @@
+using Volo.Abp.Http.Client;
+
+namespace LINGYUN.Abp.Dapr.Actors
+{
+ public class AbpDaprRemoteServiceOptions
+ {
+ public RemoteServiceConfigurationDictionary RemoteServices { get; set; }
+
+ public AbpDaprRemoteServiceOptions()
+ {
+ RemoteServices = new RemoteServiceConfigurationDictionary();
+ }
+ }
+}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/DaprActorProxyAuthenticateContext.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/DaprActorProxyAuthenticateContext.cs
deleted file mode 100644
index db63deed0..000000000
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/DaprActorProxyAuthenticateContext.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using LINGYUN.Abp.Dapr.Actors.DynamicProxying;
-
-namespace LINGYUN.Abp.Dapr.Actors.Authentication
-{
- public class DaprActorProxyAuthenticateContext
- {
- public DaprHttpClientHandler Handler { get; }
- public DaprActorConfiguration RemoteService { get; }
-
- public string RemoteServiceName { get; }
- public DaprActorProxyAuthenticateContext(
- DaprHttpClientHandler handler,
- DaprActorConfiguration remoteService,
- string remoteServiceName)
- {
- Handler = handler;
- RemoteService = remoteService;
- RemoteServiceName = remoteServiceName;
- }
- }
-}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/IDaprActorProxyAuthenticator.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/IDaprActorProxyAuthenticator.cs
deleted file mode 100644
index 71a465f46..000000000
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/IDaprActorProxyAuthenticator.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System.Threading.Tasks;
-
-namespace LINGYUN.Abp.Dapr.Actors.Authentication
-{
- public interface IDaprActorProxyAuthenticator
- {
- Task AuthenticateAsync(DaprActorProxyAuthenticateContext context);
- }
-}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/NullDaprActorProxyAuthenticator.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/NullDaprActorProxyAuthenticator.cs
deleted file mode 100644
index c2945e5ac..000000000
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/Authentication/NullDaprActorProxyAuthenticator.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System.Threading.Tasks;
-using Volo.Abp.DependencyInjection;
-
-namespace LINGYUN.Abp.Dapr.Actors.Authentication
-{
- [Dependency(TryRegister = true)]
- public class NullDaprActorProxyAuthenticator : IDaprActorProxyAuthenticator, ISingletonDependency
- {
- public Task AuthenticateAsync(DaprActorProxyAuthenticateContext context)
- {
- return Task.CompletedTask;
- }
- }
-}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprActorConfiguration.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprActorConfiguration.cs
deleted file mode 100644
index 4bc66132b..000000000
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprActorConfiguration.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using System.Collections.Generic;
-
-namespace LINGYUN.Abp.Dapr.Actors
-{
- public class DaprActorConfiguration : Dictionary
- {
- ///
- /// Base ActorId.
- ///
- public string ActorId
- {
- get => this.GetOrDefault(nameof(ActorId));
- set => this[nameof(ActorId)] = value;
- }
-
- ///
- /// Base Url.
- ///
- public string BaseUrl
- {
- get => this.GetOrDefault(nameof(BaseUrl));
- set => this[nameof(BaseUrl)] = value;
- }
-
- public DaprActorConfiguration()
- {
- }
-
- public DaprActorConfiguration(
- string actorId,
- string baseUrl)
- {
- this[nameof(ActorId)] = actorId;
- this[nameof(BaseUrl)] = baseUrl;
- }
- }
-}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprActorConfigurationDictionary.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprActorConfigurationDictionary.cs
deleted file mode 100644
index d0e9198b6..000000000
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprActorConfigurationDictionary.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System.Collections.Generic;
-using Volo.Abp;
-
-namespace LINGYUN.Abp.Dapr.Actors
-{
- public class DaprActorConfigurationDictionary : Dictionary
- {
- public const string DefaultName = "Default";
-
- public DaprActorConfiguration Default
- {
- get => this.GetOrDefault(DefaultName);
- set => this[DefaultName] = value;
- }
-
- public DaprActorConfiguration GetConfigurationOrDefault(string name)
- {
- return this.GetOrDefault(name)
- ?? Default
- ?? throw new AbpException($"Dapr service '{name}' was not found and there is no default configuration.");
- }
- }
-}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DaprHttpClientHandler.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DaprHttpClientHandler.cs
index 5b376e8b8..69f993eac 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DaprHttpClientHandler.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DaprHttpClientHandler.cs
@@ -1,5 +1,6 @@
using System;
using System.Net.Http;
+using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
@@ -7,10 +8,10 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
{
public class DaprHttpClientHandler : HttpClientHandler
{
- private Action _preConfigureInvoke;
- protected Action PreConfigureInvoke => _preConfigureInvoke;
+ private Func _preConfigureInvoke;
+ protected Func PreConfigureInvoke => _preConfigureInvoke;
- public virtual void PreConfigure(Action config)
+ public virtual void PreConfigure(Func config)
{
if (_preConfigureInvoke == null)
{
@@ -27,12 +28,27 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
PreConfigure(request =>
{
request.Headers.Add(key, value);
+
+ return Task.CompletedTask;
+ });
+ }
+
+ public void AcceptLanguage(string value)
+ {
+ PreConfigure(request =>
+ {
+ request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(value));
+
+ return Task.CompletedTask;
});
}
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
- PreConfigureInvoke?.Invoke(request);
+ if (PreConfigureInvoke != null)
+ {
+ await PreConfigureInvoke(request);
+ }
return await base.SendAsync(request, cancellationToken);
}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs
index 28116dfa5..49180fb82 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs
@@ -1,6 +1,5 @@
using Dapr.Actors;
using Dapr.Actors.Client;
-using LINGYUN.Abp.Dapr.Actors.Authentication;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
@@ -8,13 +7,14 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
-using System.Net.Http.Headers;
using System.Reflection;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Http;
+using Volo.Abp.Http.Client.Authentication;
+using Volo.Abp.Http.Client.DynamicProxying;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading;
@@ -24,22 +24,24 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
where TService: IActor
{
protected ICurrentTenant CurrentTenant { get; }
- protected AbpDaprActorOptions DaprActorOptions { get; }
+ protected AbpDaprRemoteServiceOptions DaprServiceOptions { get; }
protected AbpDaprActorProxyOptions DaprActorProxyOptions { get; }
- protected IDaprActorProxyAuthenticator ActoryProxyAuthenticator { get; }
-
+ protected IDynamicProxyHttpClientFactory HttpClientFactory { get; }
+ protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; }
public ILogger> Logger { get; set; }
public DynamicDaprActorProxyInterceptor(
IOptions daprActorProxyOptions,
- IOptionsSnapshot daprActorOptions,
- IDaprActorProxyAuthenticator actorProxyAuthenticator,
+ IOptionsSnapshot daprActorOptions,
+ IDynamicProxyHttpClientFactory httpClientFactory,
+ IRemoteServiceHttpClientAuthenticator clientAuthenticator,
ICurrentTenant currentTenant)
{
CurrentTenant = currentTenant;
- ActoryProxyAuthenticator = actorProxyAuthenticator;
+ HttpClientFactory = httpClientFactory;
+ ClientAuthenticator = clientAuthenticator;
DaprActorProxyOptions = daprActorProxyOptions.Value;
- DaprActorOptions = daprActorOptions.Value;
+ DaprServiceOptions = daprActorOptions.Value;
Logger = NullLogger>.Instance;
}
@@ -66,7 +68,13 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
{
// 获取Actor配置
var actorProxyConfig = DaprActorProxyOptions.ActorProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicDaprActorProxyConfig for {typeof(TService).FullName}.");
- var remoteServiceConfig = DaprActorOptions.RemoteActors.GetConfigurationOrDefault(actorProxyConfig.RemoteServiceName);
+ var remoteServiceConfig = DaprServiceOptions.RemoteServices.GetConfigurationOrDefault(actorProxyConfig.RemoteServiceName);
+
+ // Actors的定义太多, 可以考虑使用默认的 BaseUrl 作为远程地址
+ if (remoteServiceConfig.BaseUrl.IsNullOrWhiteSpace())
+ {
+ throw new AbpException($"Could not get BaseUrl for {actorProxyConfig.RemoteServiceName} Or Default.");
+ }
var actorProxyOptions = new ActorProxyOptions
{
@@ -77,35 +85,48 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
// 添加请求头用于传递状态
// TODO: Actor一次只能处理一个请求,使用状态管理来传递状态的可行性?
var httpClientHandler = new DaprHttpClientHandler();
-
- // 身份认证处理
- await ActoryProxyAuthenticator.AuthenticateAsync(
- new DaprActorProxyAuthenticateContext(
- httpClientHandler, remoteServiceConfig, actorProxyConfig.RemoteServiceName));
AddHeaders(httpClientHandler);
+ httpClientHandler.PreConfigure(async (requestMessage) =>
+ {
+ // 占位
+ var httpClient = HttpClientFactory.Create(AbpDaprActorsModule.DaprHttpClient);
+
+ await ClientAuthenticator.Authenticate(
+ new RemoteServiceHttpClientAuthenticateContext(
+ httpClient,
+ requestMessage,
+ remoteServiceConfig,
+ actorProxyConfig.RemoteServiceName));
+ // 标头
+ if (requestMessage.Headers.Authorization == null &&
+ httpClient.DefaultRequestHeaders.Authorization != null)
+ {
+ requestMessage.Headers.Authorization = httpClient.DefaultRequestHeaders.Authorization;
+ }
+ });
+
// 代理工厂
var proxyFactory = new ActorProxyFactory(actorProxyOptions, (HttpMessageHandler)httpClientHandler);
- await MakeRequestAsync(invocation, proxyFactory, remoteServiceConfig);
+ await MakeRequestAsync(invocation, proxyFactory);
}
private async Task MakeRequestAsync(
IAbpMethodInvocation invocation,
- ActorProxyFactory proxyFactory,
- DaprActorConfiguration configuration
+ ActorProxyFactory proxyFactory
)
{
- var actorId = new ActorId(configuration.ActorId);
-
var invokeType = typeof(TService);
+
// 约定的 RemoteServiceAttribute 为Actor名称
var remoteServiceAttr = invokeType.GetTypeInfo().GetCustomAttribute();
var actorType = remoteServiceAttr != null
? remoteServiceAttr.Name
: invokeType.Name;
-
+
+ var actorId = new ActorId(invokeType.FullName);
try
{
@@ -155,7 +176,7 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name;
if (!currentCulture.IsNullOrEmpty())
{
- handler.PreConfigure(request => request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(currentCulture)));
+ handler.AcceptLanguage(currentCulture);
}
}
}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprActorProxyExtensions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprActorProxyExtensions.cs
index 0163be7e3..85090054c 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprActorProxyExtensions.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprActorProxyExtensions.cs
@@ -8,6 +8,7 @@ using System.Linq;
using System.Reflection;
using Volo.Abp;
using Volo.Abp.Castle.DynamicProxy;
+using Volo.Abp.Http.Client;
using Volo.Abp.Validation;
namespace Microsoft.Extensions.DependencyInjection
@@ -19,7 +20,7 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddDaprActorProxies(
[NotNull] this IServiceCollection services,
[NotNull] Assembly assembly,
- [NotNull] string remoteServiceConfigurationName = DaprActorConfigurationDictionary.DefaultName,
+ [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName,
bool asDefaultServices = true)
{
Check.NotNull(services, nameof(assembly));
@@ -40,7 +41,7 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddDaprActorProxy(
[NotNull] this IServiceCollection services,
- [NotNull] string remoteServiceConfigurationName = DaprActorConfigurationDictionary.DefaultName,
+ [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName,
bool asDefaultService = true)
{
return services.AddDaprActorProxy(
@@ -53,7 +54,7 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddDaprActorProxy(
[NotNull] this IServiceCollection services,
[NotNull] Type type,
- [NotNull] string remoteServiceConfigurationName = DaprActorConfigurationDictionary.DefaultName,
+ [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName,
bool asDefaultService = true)
{
Check.NotNull(services, nameof(services));
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 1caf070ac..b792a1d10 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,18 +1,18 @@
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
using Volo.Abp.Http.Client;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Dapr.Client
{
[DependsOn(
- typeof(AbpHttpClientModule))]
+ typeof(AbpHttpClientModule)
+ )]
public class AbpDaprClientModule : AbpModule
{
///
/// 与AbpHttpClient集成,创建一个命名HttpClient
///
- internal const string DaprHttpClient = "_AbpDaprClient";
+ internal const string DaprHttpClient = "_AbpDaprProxyClient";
public override void ConfigureServices(ServiceConfigurationContext context)
{
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 5f2b3f18f..d9f9adf3f 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
@@ -172,9 +172,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
new RemoteServiceHttpClientAuthenticateContext(
httpClient,
requestMessage,
- new RemoteServiceConfiguration(
- remoteServiceConfig.BaseUrl,
- remoteServiceConfig.Version),
+ remoteServiceConfig,
clientConfig.RemoteServiceName
)
);
diff --git a/aspnet-core/modules/dapr/README.md b/aspnet-core/modules/dapr/README.md
index c46f805a4..4fbc32058 100644
--- a/aspnet-core/modules/dapr/README.md
+++ b/aspnet-core/modules/dapr/README.md
@@ -75,9 +75,8 @@ dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run
```json
{
- "RemoteActors": {
- "System": {
- "ActorId": "1",
+ "RemoteServices": {
+ "Shop": {
"BaseUrl": "http://127.0.0.1:50000"
}
}
@@ -99,7 +98,7 @@ public class SystemActorClientModule : AbpModule
// 注册代理类似于 Volo.Abp.Http.Client 模块
context.Services.AddDaprActorProxies(
typeof(SystemActorInterfaceModule).Assembly, // 搜索 SystemActorInterfaceModule 模块下的IActor定义
- RemoteServiceName
+ "Shop"
);
}
}
diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN.Abp.Dapr.Actors.Tests.csproj b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN.Abp.Dapr.Actors.Tests.csproj
new file mode 100644
index 000000000..1616c1d84
--- /dev/null
+++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN.Abp.Dapr.Actors.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.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/AbpDaprActorsTestBase.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/AbpDaprActorsTestBase.cs
new file mode 100644
index 000000000..b8ee1f05f
--- /dev/null
+++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/AbpDaprActorsTestBase.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.Actors.Tests
+{
+ public class AbpDaprActorsTestBase : 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.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/AbpDaprActorsTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/AbpDaprActorsTestModule.cs
new file mode 100644
index 000000000..951d73118
--- /dev/null
+++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/AbpDaprActorsTestModule.cs
@@ -0,0 +1,33 @@
+using LINGYUN.Abp.Tests;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using System.IO;
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.Dapr.Actors.Tests
+{
+ [DependsOn(
+ typeof(AbpDaprTestModule),
+ typeof(AbpTestsBaseModule),
+ typeof(AbpDaprActorsModule))]
+ public class AbpDaprActorsTestModule : 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.AddDaprActorProxies(
+ typeof(AbpDaprTestModule).Assembly,
+ "TestDapr");
+ }
+ }
+}
diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/TestActorsTests.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/TestActorsTests.cs
new file mode 100644
index 000000000..fdcd1da32
--- /dev/null
+++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Actors.Tests/LINGYUN/Abp/Dapr/Actors/Tests/TestActorsTests.cs
@@ -0,0 +1,39 @@
+using Microsoft.Extensions.DependencyInjection;
+using Shouldly;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace LINGYUN.Abp.Dapr.Actors.Tests
+{
+ public class TestAppServiceTests : AbpDaprActorsTestBase
+ {
+ private readonly ITestActor _actor;
+
+ public TestAppServiceTests()
+ {
+ _actor = GetRequiredService();
+ }
+
+ [Fact]
+ public async Task Get_Result_Items_Count_Should_5()
+ {
+ var result = await _actor.GetAsync();
+
+ result.Count.ShouldBe(5);
+ }
+
+ [Fact]
+ public async Task Update_Result_Value_Should_Value_Updated_1()
+ {
+ var result = await _actor.UpdateAsync();
+
+ result.Value.ShouldBe("value:updated:1");
+ }
+
+ public override void Dispose()
+ {
+ _ = _actor.ClearAsync();
+ base.Dispose();
+ }
+ }
+}
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
index bfbedf609..17584125a 100644
--- 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
@@ -13,11 +13,11 @@ namespace LINGYUN.Abp.Dapr.Actors
{
}
- public async Task> GetAsync()
+ public async Task> GetAsync()
{
var values = await GetValuesByStateAsync();
- return new ListResultDto(values);
+ return values;
}
public async Task UpdateAsync()
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
index 87960d107..30bb753de 100644
--- 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
@@ -1,14 +1,14 @@
using Dapr.Actors;
+using System.Collections.Generic;
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> GetAsync();
Task UpdateAsync();
diff --git a/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/NameValue.cs b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/NameValue.cs
new file mode 100644
index 000000000..3c6272e58
--- /dev/null
+++ b/aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/NameValue.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+
+namespace LINGYUN.Abp.Dapr
+{
+ [System.Serializable]
+ public class NameValue
+ {
+ public string Key { get; set; }
+ public string Value { get; set; }
+ public NameValue() { }
+ public NameValue(string key, string value)
+ {
+ Key = key;
+ Value = value;
+ }
+ }
+}