From 63c60011ddaacf06f1eab307dd607476e87fcb5b Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Sun, 12 Jun 2022 16:18:16 +0800 Subject: [PATCH] Remove `IInventoryActorProvider` and `IInventoryGrainProvider` --- .../DaprActorsProductInventoryProvider.cs | 12 +- .../IInventoryActorProvider.cs | 10 -- .../InventoryActorProvider.cs | 17 --- .../TestActorProxyFactory.cs | 50 +++++++ .../TestInventoryActorProvider.cs | 26 ---- .../IInventoryGrainProvider.cs | 9 -- .../InventoryGrainProvider.cs | 21 --- .../OrleansGrainsProductInventoryProvider.cs | 11 +- .../TestGrainFactory.cs | 136 ++++++++++++++++++ .../TestInventoryGrainProvider.cs | 25 ---- 10 files changed, 199 insertions(+), 118 deletions(-) delete mode 100644 plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/IInventoryActorProvider.cs delete mode 100644 plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/InventoryActorProvider.cs create mode 100644 plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestActorProxyFactory.cs delete mode 100644 plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestInventoryActorProvider.cs delete mode 100644 plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/IInventoryGrainProvider.cs delete mode 100644 plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/InventoryGrainProvider.cs create mode 100644 plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestGrainFactory.cs delete mode 100644 plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestInventoryGrainProvider.cs diff --git a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/DaprActorsProductInventoryProvider.cs b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/DaprActorsProductInventoryProvider.cs index 14d4faa5..86ebb124 100644 --- a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/DaprActorsProductInventoryProvider.cs +++ b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/DaprActorsProductInventoryProvider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Dapr.Actors; +using Dapr.Actors.Client; using EasyAbp.EShop.Plugins.Inventories.DaprActors; using EasyAbp.EShop.Products.ProductInventories; using Microsoft.Extensions.Logging; @@ -11,6 +12,7 @@ namespace EasyAbp.EShop.Products.DaprActorsInventory; public class DaprActorsProductInventoryProvider : IProductInventoryProvider, ITransientDependency { + public static string ActorType { get; set; } = "InventoryActor"; public static string DaprActorsProductInventoryProviderName { get; set; } = "DaprActors"; public static string DaprActorsProductInventoryProviderDisplayName { get; set; } = "DaprActors"; public static string DaprActorsProductInventoryProviderDescription { get; set; } = "DaprActors"; @@ -18,13 +20,13 @@ public class DaprActorsProductInventoryProvider : IProductInventoryProvider, ITr public string InventoryProviderName { get; } = DaprActorsProductInventoryProviderName; private readonly ILogger _logger; - protected IInventoryActorProvider InventoryActorProvider { get; } + protected IActorProxyFactory ActorProxyFactory { get; } public DaprActorsProductInventoryProvider( - IInventoryActorProvider inventoryActorProvider, + IActorProxyFactory actorProxyFactory, ILogger logger) { - InventoryActorProvider = inventoryActorProvider; + ActorProxyFactory = actorProxyFactory; _logger = logger; } @@ -98,9 +100,9 @@ public class DaprActorsProductInventoryProvider : IProductInventoryProvider, ITr return true; } - protected virtual async Task GetActorAsync(InventoryQueryModel model) + protected virtual Task GetActorAsync(InventoryQueryModel model) { - return await InventoryActorProvider.GetAsync(GetActorId(model)); + return Task.FromResult(ActorProxyFactory.CreateActorProxy(GetActorId(model), ActorType)); } protected virtual ActorId GetActorId(InventoryQueryModel model) diff --git a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/IInventoryActorProvider.cs b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/IInventoryActorProvider.cs deleted file mode 100644 index fc1dc827..00000000 --- a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/IInventoryActorProvider.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Threading.Tasks; -using Dapr.Actors; -using EasyAbp.EShop.Plugins.Inventories.DaprActors; - -namespace EasyAbp.EShop.Products.DaprActorsInventory; - -public interface IInventoryActorProvider -{ - Task GetAsync(ActorId actorId); -} \ No newline at end of file diff --git a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/InventoryActorProvider.cs b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/InventoryActorProvider.cs deleted file mode 100644 index 16dd18f1..00000000 --- a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/InventoryActorProvider.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading.Tasks; -using Dapr.Actors; -using Dapr.Actors.Client; -using EasyAbp.EShop.Plugins.Inventories.DaprActors; -using Volo.Abp.DependencyInjection; - -namespace EasyAbp.EShop.Products.DaprActorsInventory; - -public class InventoryActorProvider : IInventoryActorProvider, ITransientDependency -{ - public static string ActorType { get; set; } = "InventoryActor"; - - public virtual Task GetAsync(ActorId actorId) - { - return Task.FromResult(ActorProxy.Create(actorId, ActorType)); - } -} \ No newline at end of file diff --git a/plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestActorProxyFactory.cs b/plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestActorProxyFactory.cs new file mode 100644 index 00000000..a2f540e5 --- /dev/null +++ b/plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestActorProxyFactory.cs @@ -0,0 +1,50 @@ +using System; +using Dapr.Actors; +using Dapr.Actors.Client; +using EasyAbp.EShop.Plugins.Inventories.DaprActors; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.DependencyInjection; + +namespace EasyAbp.EShop.Products.DaprActorsInventory.Domain; + +[Dependency(ReplaceServices = true)] +public class TestActorProxyFactory : IActorProxyFactory, ITransientDependency +{ + private IInventoryActor Actor { get; set; } + + private readonly IServiceProvider _serviceProvider; + + public TestActorProxyFactory(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public TActorInterface CreateActorProxy(ActorId actorId, string actorType, + ActorProxyOptions options = null) where TActorInterface : IActor + { + if (typeof(TActorInterface) != typeof(IInventoryActor)) + { + throw new ApplicationException(); + } + + if (Actor is not null) + { + return (TActorInterface)Actor; + } + + Actor = _serviceProvider.GetRequiredService(); + + return (TActorInterface)Actor; + } + + public object CreateActorProxy(ActorId actorId, Type actorInterfaceType, string actorType, + ActorProxyOptions options = null) + { + throw new NotSupportedException(); + } + + public ActorProxy Create(ActorId actorId, string actorType, ActorProxyOptions options = null) + { + throw new NotSupportedException(); + } +} \ No newline at end of file diff --git a/plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestInventoryActorProvider.cs b/plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestInventoryActorProvider.cs deleted file mode 100644 index 1b889758..00000000 --- a/plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestInventoryActorProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Threading.Tasks; -using Dapr.Actors; -using EasyAbp.EShop.Plugins.Inventories.DaprActors; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.DependencyInjection; - -namespace EasyAbp.EShop.Products.DaprActorsInventory.Domain; - -[Dependency(ReplaceServices = true)] -public class TestInventoryActorProvider : IInventoryActorProvider, ITransientDependency -{ - private IInventoryActor Actor { get; set; } - - private readonly IServiceProvider _serviceProvider; - - public TestInventoryActorProvider(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - } - - public Task GetAsync(ActorId actorId) - { - return Task.FromResult(Actor ??= _serviceProvider.GetRequiredService()); - } -} \ No newline at end of file diff --git a/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/IInventoryGrainProvider.cs b/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/IInventoryGrainProvider.cs deleted file mode 100644 index 5f5d1966..00000000 --- a/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/IInventoryGrainProvider.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; -using EasyAbp.EShop.Plugins.Inventories.OrleansGrains; - -namespace EasyAbp.EShop.Products.OrleansGrainsInventory; - -public interface IInventoryGrainProvider -{ - Task GetAsync(string grainKey); -} \ No newline at end of file diff --git a/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/InventoryGrainProvider.cs b/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/InventoryGrainProvider.cs deleted file mode 100644 index 0ef6d00f..00000000 --- a/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/InventoryGrainProvider.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Threading.Tasks; -using EasyAbp.EShop.Plugins.Inventories.OrleansGrains; -using Orleans; -using Volo.Abp.DependencyInjection; - -namespace EasyAbp.EShop.Products.OrleansGrainsInventory; - -public class InventoryGrainProvider : IInventoryGrainProvider, ITransientDependency -{ - private readonly IGrainFactory _grainFactory; - - public InventoryGrainProvider(IGrainFactory grainFactory) - { - _grainFactory = grainFactory; - } - - public virtual Task GetAsync(string grainKey) - { - return Task.FromResult(_grainFactory.GetGrain(grainKey)); - } -} \ No newline at end of file diff --git a/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/OrleansGrainsProductInventoryProvider.cs b/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/OrleansGrainsProductInventoryProvider.cs index 54a95b54..19a7edb2 100644 --- a/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/OrleansGrainsProductInventoryProvider.cs +++ b/plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/OrleansGrainsProductInventoryProvider.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using EasyAbp.EShop.Plugins.Inventories.OrleansGrains; using EasyAbp.EShop.Products.ProductInventories; using Microsoft.Extensions.Logging; +using Orleans; using Volo.Abp.DependencyInjection; namespace EasyAbp.EShop.Products.OrleansGrainsInventory; @@ -17,13 +18,13 @@ public class OrleansGrainsProductInventoryProvider : IProductInventoryProvider, public string InventoryProviderName { get; } = OrleansGrainsProductInventoryProviderName; private readonly ILogger _logger; - protected IInventoryGrainProvider InventoryGrainProvider { get; } + protected IGrainFactory GrainFactory { get; } public OrleansGrainsProductInventoryProvider( - IInventoryGrainProvider inventoryGrainProvider, + IGrainFactory grainFactory, ILogger logger) { - InventoryGrainProvider = inventoryGrainProvider; + GrainFactory = grainFactory; _logger = logger; } @@ -97,9 +98,9 @@ public class OrleansGrainsProductInventoryProvider : IProductInventoryProvider, return true; } - protected virtual async Task GetGrainAsync(InventoryQueryModel model) + protected virtual Task GetGrainAsync(InventoryQueryModel model) { - return await InventoryGrainProvider.GetAsync(GetGrainId(model)); + return Task.FromResult(GrainFactory.GetGrain(GetGrainId(model))); } protected virtual string GetGrainId(InventoryQueryModel model) diff --git a/plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestGrainFactory.cs b/plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestGrainFactory.cs new file mode 100644 index 00000000..19973fc4 --- /dev/null +++ b/plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestGrainFactory.cs @@ -0,0 +1,136 @@ +using System; +using System.Threading.Tasks; +using EasyAbp.EShop.Plugins.Inventories.OrleansGrains; +using Microsoft.Extensions.DependencyInjection; +using Orleans; +using Orleans.Runtime; +using Volo.Abp.DependencyInjection; + +namespace EasyAbp.EShop.Products.OrleansGrainsInventory.Domain; + +[Dependency(ReplaceServices = true)] +public class TestGrainFactory : IGrainFactory, ITransientDependency +{ + private IInventoryGrain Grain { get; set; } + + private readonly IServiceProvider _serviceProvider; + + public TestGrainFactory(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public TGrainInterface GetGrain(Guid primaryKey, string grainClassNamePrefix = null) + where TGrainInterface : IGrainWithGuidKey + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(long primaryKey, string grainClassNamePrefix = null) + where TGrainInterface : IGrainWithIntegerKey + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(string primaryKey, string grainClassNamePrefix = null) + where TGrainInterface : IGrainWithStringKey + { + if (typeof(TGrainInterface) != typeof(IInventoryGrain)) + { + throw new ApplicationException(); + } + + if (Grain is not null) + { + return (TGrainInterface)Grain; + } + + Grain = _serviceProvider.GetRequiredService(); + + return (TGrainInterface)Grain; + } + + public TGrainInterface GetGrain(Guid primaryKey, string keyExtension, + string grainClassNamePrefix = null) where TGrainInterface : IGrainWithGuidCompoundKey + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(long primaryKey, string keyExtension, + string grainClassNamePrefix = null) where TGrainInterface : IGrainWithIntegerCompoundKey + { + throw new NotSupportedException(); + } + + public async Task CreateObjectReference(IGrainObserver obj) + where TGrainObserverInterface : IGrainObserver + { + throw new NotSupportedException(); + } + + public async Task DeleteObjectReference(IGrainObserver obj) + where TGrainObserverInterface : IGrainObserver + { + throw new NotSupportedException(); + } + + public void BindGrainReference(IAddressable grain) + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(Type grainInterfaceType, Guid grainPrimaryKey) + where TGrainInterface : IGrain + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(Type grainInterfaceType, long grainPrimaryKey) + where TGrainInterface : IGrain + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(Type grainInterfaceType, string grainPrimaryKey) + where TGrainInterface : IGrain + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(Type grainInterfaceType, Guid grainPrimaryKey, string keyExtension) + where TGrainInterface : IGrain + { + throw new NotSupportedException(); + } + + public TGrainInterface GetGrain(Type grainInterfaceType, long grainPrimaryKey, string keyExtension) + where TGrainInterface : IGrain + { + throw new NotSupportedException(); + } + + public IGrain GetGrain(Type grainInterfaceType, Guid grainPrimaryKey) + { + throw new NotSupportedException(); + } + + public IGrain GetGrain(Type grainInterfaceType, long grainPrimaryKey) + { + throw new NotSupportedException(); + } + + public IGrain GetGrain(Type grainInterfaceType, string grainPrimaryKey) + { + throw new NotSupportedException(); + } + + public IGrain GetGrain(Type grainInterfaceType, Guid grainPrimaryKey, string keyExtension) + { + throw new NotSupportedException(); + } + + public IGrain GetGrain(Type grainInterfaceType, long grainPrimaryKey, string keyExtension) + { + throw new NotSupportedException(); + } +} \ No newline at end of file diff --git a/plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestInventoryGrainProvider.cs b/plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestInventoryGrainProvider.cs deleted file mode 100644 index 42c9990e..00000000 --- a/plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestInventoryGrainProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Threading.Tasks; -using EasyAbp.EShop.Plugins.Inventories.OrleansGrains; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.DependencyInjection; - -namespace EasyAbp.EShop.Products.OrleansGrainsInventory.Domain; - -[Dependency(ReplaceServices = true)] -public class TestInventoryGrainProvider : IInventoryGrainProvider, ITransientDependency -{ - private IInventoryGrain Grain { get; set; } - - private readonly IServiceProvider _serviceProvider; - - public TestInventoryGrainProvider(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - } - - public Task GetAsync(string grainKey) - { - return Task.FromResult(Grain ??= _serviceProvider.GetRequiredService()); - } -} \ No newline at end of file