diff --git a/Directory.Build.props b/Directory.Build.props
index 7f008f29..98938073 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -3,7 +3,7 @@
5.1.3
2.5.3
- 2.0.11
+ 2.0.12
0.8.2
1.7.0
3.6.2
diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs
index 2e432276..f8759d9a 100644
--- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs
+++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application/EasyAbp/EShop/Orders/Orders/OrderAppService.cs
@@ -90,6 +90,8 @@ namespace EasyAbp.EShop.Orders.Orders
var productDict = await GetProductDictionaryAsync(input.OrderLines.Select(dto => dto.ProductId).ToList());
+ ThrowIfExistFlashSalesProduct(productDict);
+
await AuthorizationService.CheckAsync(
new OrderCreationResource
{
@@ -118,7 +120,15 @@ namespace EasyAbp.EShop.Orders.Orders
return await MapToGetOutputDtoAsync(order);
}
-
+
+ protected virtual void ThrowIfExistFlashSalesProduct(Dictionary productDict)
+ {
+ if (productDict.Any(x => x.Value.InventoryStrategy is InventoryStrategy.FlashSales))
+ {
+ throw new BusinessException(OrdersErrorCodes.ExistFlashSalesProduct);
+ }
+ }
+
protected virtual async Task DiscountOrderAsync(Order order, Dictionary productDict)
{
foreach (var provider in LazyServiceProvider.LazyGetService>())
diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/en.json b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/en.json
index 817ec042..622b7f6d 100644
--- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/en.json
+++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/en.json
@@ -48,6 +48,7 @@
"EasyAbp.EShop.Orders:InvalidPayment": "The payment {paymentId} has invalid configurations for the order {orderId}.",
"EasyAbp.EShop.Orders:InvalidRefundAmount": "The refund amount ({amount}) is invalid.",
"EasyAbp.EShop.Orders:InvalidRefundQuantity": "The refund quantity ({quantity}) is invalid.",
- "EasyAbp.EShop.Orders:OrderIsInWrongStage": "The order {orderId} is in the wrong stage."
+ "EasyAbp.EShop.Orders:OrderIsInWrongStage": "The order {orderId} is in the wrong stage.",
+ "EasyAbp.EShop.Orders:ExistFlashSalesProduct": "Exist unexpected flash-sales product"
}
}
\ No newline at end of file
diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hans.json b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hans.json
index 75080471..e6c3385d 100644
--- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hans.json
+++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hans.json
@@ -48,6 +48,7 @@
"EasyAbp.EShop.Orders:InvalidPayment": "付款{paymentId}有无效的订单配置{orderId}",
"EasyAbp.EShop.Orders:InvalidRefundAmount": "退款金额({amount})无效",
"EasyAbp.EShop.Orders:InvalidRefundQuantity": "退款数量({quantity})无效",
- "EasyAbp.EShop.Orders:OrderIsInWrongStage": "订单{orderId}处于错误的阶段"
+ "EasyAbp.EShop.Orders:OrderIsInWrongStage": "订单{orderId}处于错误的阶段",
+ "EasyAbp.EShop.Orders:ExistFlashSalesProduct": "清单中不允许存在闪购产品"
}
}
\ No newline at end of file
diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hant.json b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hant.json
index f06deea8..a5efa664 100644
--- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hant.json
+++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Localization/Orders/zh-Hant.json
@@ -48,6 +48,7 @@
"EasyAbp.EShop.Orders:InvalidPayment": "付款{paymentId}有無效的訂單配置{orderId}",
"EasyAbp.EShop.Orders:InvalidRefundAmount": "退款金額({amount})無效",
"EasyAbp.EShop.Orders:InvalidRefundQuantity": "退款數量({quantity})無效",
- "EasyAbp.EShop.Orders:OrderIsInWrongStage": "訂單{orderId}處於錯誤的階段"
+ "EasyAbp.EShop.Orders:OrderIsInWrongStage": "訂單{orderId}處於錯誤的階段",
+ "EasyAbp.EShop.Orders:ExistFlashSalesProduct": "清單中不允許存在閃購產品"
}
}
\ No newline at end of file
diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/OrdersErrorCodes.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/OrdersErrorCodes.cs
index 8a1af850..d87dd982 100644
--- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/OrdersErrorCodes.cs
+++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/OrdersErrorCodes.cs
@@ -11,5 +11,6 @@
public const string InvalidRefundAmount = "EasyAbp.EShop.Orders:InvalidRefundAmount";
public const string InvalidRefundQuantity = "EasyAbp.EShop.Orders:InvalidRefundQuantity";
public const string OrderIsInWrongStage = "EasyAbp.EShop.Orders:OrderIsInWrongStage";
+ public const string ExistFlashSalesProduct = "EasyAbp.EShop.Orders:ExistFlashSalesProduct";
}
}
diff --git a/modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/OrderAppServiceTests.cs b/modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/OrderAppServiceTests.cs
index 18e5b70b..b7f2eebd 100644
--- a/modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/OrderAppServiceTests.cs
+++ b/modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/OrderAppServiceTests.cs
@@ -11,6 +11,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shouldly;
+using Volo.Abp;
using Volo.Abp.Timing;
using Xunit;
@@ -21,6 +22,8 @@ namespace EasyAbp.EShop.Orders.Orders
private readonly IClock _clock;
private readonly IOrderAppService _orderAppService;
+ private ProductDto Product1 { get; set; }
+
public OrderAppServiceTests()
{
_clock = GetRequiredService();
@@ -29,8 +32,7 @@ namespace EasyAbp.EShop.Orders.Orders
protected override void AfterAddApplication(IServiceCollection services)
{
- var productAppService = Substitute.For();
- productAppService.GetAsync(OrderTestData.Product1Id).Returns(Task.FromResult(new ProductDto
+ Product1 = new ProductDto
{
CreationTime = DateTime.Now,
IsPublished = true,
@@ -79,10 +81,13 @@ namespace EasyAbp.EShop.Orders.Orders
},
InventoryStrategy = InventoryStrategy.NoNeed,
LastModificationTime = OrderTestData.ProductLastModificationTime
- }));
+ };
+
+ var productAppService = Substitute.For();
+ productAppService.GetAsync(OrderTestData.Product1Id).Returns(Task.FromResult(Product1));
services.AddTransient(_ => productAppService);
-
+
var productDetailAppService = Substitute.For();
productDetailAppService.GetAsync(OrderTestData.ProductDetail1Id).Returns(Task.FromResult(
@@ -186,7 +191,7 @@ namespace EasyAbp.EShop.Orders.Orders
orderLine1.ProductDetailModificationTime.ShouldBe(OrderTestData.ProductDetailLastModificationTime);
orderLine1.RefundAmount.ShouldBe(0m);
orderLine1.RefundedQuantity.ShouldBe(0);
-
+
var orderLine2 = response.OrderLines.Single(x => x.ProductSkuId == OrderTestData.ProductSku2Id);
orderLine2.ProductDetailId.ShouldBe(OrderTestData.ProductDetail2Id);
});
@@ -245,7 +250,7 @@ namespace EasyAbp.EShop.Orders.Orders
response.OrderStatus.ShouldBe(OrderStatus.Canceled);
response.CanceledTime.ShouldNotBeNull();
response.CancellationReason.ShouldBe("Repeat orders.");
-
+
UsingDbContext(db =>
{
var order = db.Orders.FirstOrDefault(o => o.Id == orderId);
@@ -280,7 +285,7 @@ namespace EasyAbp.EShop.Orders.Orders
order.SetPaymentId(null);
await orderRepository.UpdateAsync(order, true);
});
-
+
var response = await _orderAppService.GetAsync(orderId);
// Assert
@@ -290,7 +295,7 @@ namespace EasyAbp.EShop.Orders.Orders
response.OrderStatus.ShouldBe(OrderStatus.Canceled);
response.CanceledTime.ShouldNotBeNull();
response.CancellationReason.ShouldBe(OrdersConsts.UnpaidAutoCancellationReason);
-
+
UsingDbContext(db =>
{
var order = db.Orders.FirstOrDefault(o => o.Id == orderId);
@@ -349,7 +354,7 @@ namespace EasyAbp.EShop.Orders.Orders
response.OrderStatus.ShouldBe(OrderStatus.Processing);
response.CanceledTime.ShouldBeNull();
response.CancellationReason.ShouldBeNull();
-
+
UsingDbContext(db =>
{
var order = db.Orders.FirstOrDefault(o => o.Id == orderId);
@@ -361,7 +366,7 @@ namespace EasyAbp.EShop.Orders.Orders
order.CancellationReason.ShouldBeNull();
});
}
-
+
[Fact]
public async Task Unpaid_Order_Should_Be_Auto_Canceled_When_Payment_Overtime()
{
@@ -404,7 +409,7 @@ namespace EasyAbp.EShop.Orders.Orders
response.OrderStatus.ShouldBe(OrderStatus.Canceled);
response.CanceledTime.ShouldNotBeNull();
response.CancellationReason.ShouldBe(OrdersConsts.UnpaidAutoCancellationReason);
-
+
UsingDbContext(db =>
{
var order = db.Orders.FirstOrDefault(o => o.Id == orderId);
@@ -416,7 +421,7 @@ namespace EasyAbp.EShop.Orders.Orders
order.CancellationReason.ShouldBe(OrdersConsts.UnpaidAutoCancellationReason);
});
}
-
+
[Fact]
public async Task Payment_Pending_Order_Should_Be_Auto_Canceled_When_Payment_Overtime()
{
@@ -461,7 +466,7 @@ namespace EasyAbp.EShop.Orders.Orders
response.OrderStatus.ShouldBe(OrderStatus.Canceled);
response.CanceledTime.ShouldNotBeNull();
response.CancellationReason.ShouldBe(OrdersConsts.UnpaidAutoCancellationReason);
-
+
UsingDbContext(db =>
{
var order = db.Orders.FirstOrDefault(o => o.Id == orderId);
@@ -497,17 +502,47 @@ namespace EasyAbp.EShop.Orders.Orders
}
}
};
-
+
await WithUnitOfWorkAsync(async () =>
{
var order = await _orderAppService.CreateAsync(createOrderDto);
var orderLine = order.OrderLines.Find(x => x.ProductSkuId == OrderTestData.ProductSku3Id);
-
+
order.ProductTotalPrice.ShouldBe(10 * 1m + 2 * TestOrderLinePriceOverrider.Sku3UnitPrice);
orderLine.ShouldNotBeNull();
orderLine.UnitPrice.ShouldBe(TestOrderLinePriceOverrider.Sku3UnitPrice);
orderLine.TotalPrice.ShouldBe(orderLine.Quantity * orderLine.UnitPrice);
});
}
+
+ [Fact]
+ public async Task Should_Not_Create_Order_With_Flash_Sales_Products()
+ {
+ var createOrderDto = new CreateOrderDto
+ {
+ StoreId = OrderTestData.Store1Id,
+ OrderLines = new List
+ {
+ new()
+ {
+ ProductId = OrderTestData.Product1Id,
+ ProductSkuId = OrderTestData.ProductSku1Id,
+ Quantity = 1
+ }
+ }
+ };
+
+ Product1.InventoryStrategy = InventoryStrategy.FlashSales;
+
+ await WithUnitOfWorkAsync(async () =>
+ {
+ var exception =
+ await Should.ThrowAsync(() => _orderAppService.CreateAsync(createOrderDto));
+
+ exception.Code.ShouldBe(OrdersErrorCodes.ExistFlashSalesProduct);
+ });
+
+ Product1.InventoryStrategy = InventoryStrategy.NoNeed;
+ }
}
}
\ No newline at end of file
diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/InventoryStrategy.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/InventoryStrategy.cs
index 301d6684..257d0b13 100644
--- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/InventoryStrategy.cs
+++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/InventoryStrategy.cs
@@ -7,6 +7,7 @@ namespace EasyAbp.EShop.Products.Products
{
NoNeed = 1,
ReduceAfterPlacing = 2,
- ReduceAfterPayment = 4
+ ReduceAfterPayment = 4,
+ FlashSales = 8
}
}
\ No newline at end of file
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