Browse Source

Merge pull request #165 from EasyAbp/remove-actor-grain-provider

Remove `IInventoryActorProvider` and `IInventoryGrainProvider`
pull/169/head
Super 4 years ago
committed by GitHub
parent
commit
b79da3abcc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/DaprActorsProductInventoryProvider.cs
  2. 10
      plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/IInventoryActorProvider.cs
  3. 17
      plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/InventoryActorProvider.cs
  4. 50
      plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestActorProxyFactory.cs
  5. 26
      plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestInventoryActorProvider.cs
  6. 9
      plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/IInventoryGrainProvider.cs
  7. 21
      plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/InventoryGrainProvider.cs
  8. 11
      plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/OrleansGrainsProductInventoryProvider.cs
  9. 136
      plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestGrainFactory.cs
  10. 25
      plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestInventoryGrainProvider.cs

12
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<DaprActorsProductInventoryProvider> _logger;
protected IInventoryActorProvider InventoryActorProvider { get; }
protected IActorProxyFactory ActorProxyFactory { get; }
public DaprActorsProductInventoryProvider(
IInventoryActorProvider inventoryActorProvider,
IActorProxyFactory actorProxyFactory,
ILogger<DaprActorsProductInventoryProvider> logger)
{
InventoryActorProvider = inventoryActorProvider;
ActorProxyFactory = actorProxyFactory;
_logger = logger;
}
@ -98,9 +100,9 @@ public class DaprActorsProductInventoryProvider : IProductInventoryProvider, ITr
return true;
}
protected virtual async Task<IInventoryActor> GetActorAsync(InventoryQueryModel model)
protected virtual Task<IInventoryActor> GetActorAsync(InventoryQueryModel model)
{
return await InventoryActorProvider.GetAsync(GetActorId(model));
return Task.FromResult(ActorProxyFactory.CreateActorProxy<IInventoryActor>(GetActorId(model), ActorType));
}
protected virtual ActorId GetActorId(InventoryQueryModel model)

10
plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/IInventoryActorProvider.cs

@ -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<IInventoryActor> GetAsync(ActorId actorId);
}

17
plugins/Inventories/DaprActors/src/EasyAbp.EShop.Products.DaprActorsInventory.Domain/EasyAbp/EShop/Products/DaprActorsInventory/InventoryActorProvider.cs

@ -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<IInventoryActor> GetAsync(ActorId actorId)
{
return Task.FromResult(ActorProxy.Create<IInventoryActor>(actorId, ActorType));
}
}

50
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<TActorInterface>(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<IInventoryActor>();
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();
}
}

26
plugins/Inventories/DaprActors/test/EasyAbp.EShop.Products.DaprActorsInventory.Domain.Tests/TestInventoryActorProvider.cs

@ -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<IInventoryActor> GetAsync(ActorId actorId)
{
return Task.FromResult(Actor ??= _serviceProvider.GetRequiredService<FakeInventoryActor>());
}
}

9
plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/IInventoryGrainProvider.cs

@ -1,9 +0,0 @@
using System.Threading.Tasks;
using EasyAbp.EShop.Plugins.Inventories.OrleansGrains;
namespace EasyAbp.EShop.Products.OrleansGrainsInventory;
public interface IInventoryGrainProvider
{
Task<IInventoryGrain> GetAsync(string grainKey);
}

21
plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain/EasyAbp/EShop/Products/OrleansGrainsInventory/InventoryGrainProvider.cs

@ -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<IInventoryGrain> GetAsync(string grainKey)
{
return Task.FromResult(_grainFactory.GetGrain<IInventoryGrain>(grainKey));
}
}

11
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<OrleansGrainsProductInventoryProvider> _logger;
protected IInventoryGrainProvider InventoryGrainProvider { get; }
protected IGrainFactory GrainFactory { get; }
public OrleansGrainsProductInventoryProvider(
IInventoryGrainProvider inventoryGrainProvider,
IGrainFactory grainFactory,
ILogger<OrleansGrainsProductInventoryProvider> logger)
{
InventoryGrainProvider = inventoryGrainProvider;
GrainFactory = grainFactory;
_logger = logger;
}
@ -97,9 +98,9 @@ public class OrleansGrainsProductInventoryProvider : IProductInventoryProvider,
return true;
}
protected virtual async Task<IInventoryGrain> GetGrainAsync(InventoryQueryModel model)
protected virtual Task<IInventoryGrain> GetGrainAsync(InventoryQueryModel model)
{
return await InventoryGrainProvider.GetAsync(GetGrainId(model));
return Task.FromResult(GrainFactory.GetGrain<IInventoryGrain>(GetGrainId(model)));
}
protected virtual string GetGrainId(InventoryQueryModel model)

136
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<TGrainInterface>(Guid primaryKey, string grainClassNamePrefix = null)
where TGrainInterface : IGrainWithGuidKey
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(long primaryKey, string grainClassNamePrefix = null)
where TGrainInterface : IGrainWithIntegerKey
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(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<FakeInventoryGrain>();
return (TGrainInterface)Grain;
}
public TGrainInterface GetGrain<TGrainInterface>(Guid primaryKey, string keyExtension,
string grainClassNamePrefix = null) where TGrainInterface : IGrainWithGuidCompoundKey
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(long primaryKey, string keyExtension,
string grainClassNamePrefix = null) where TGrainInterface : IGrainWithIntegerCompoundKey
{
throw new NotSupportedException();
}
public async Task<TGrainObserverInterface> CreateObjectReference<TGrainObserverInterface>(IGrainObserver obj)
where TGrainObserverInterface : IGrainObserver
{
throw new NotSupportedException();
}
public async Task DeleteObjectReference<TGrainObserverInterface>(IGrainObserver obj)
where TGrainObserverInterface : IGrainObserver
{
throw new NotSupportedException();
}
public void BindGrainReference(IAddressable grain)
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(Type grainInterfaceType, Guid grainPrimaryKey)
where TGrainInterface : IGrain
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(Type grainInterfaceType, long grainPrimaryKey)
where TGrainInterface : IGrain
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(Type grainInterfaceType, string grainPrimaryKey)
where TGrainInterface : IGrain
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(Type grainInterfaceType, Guid grainPrimaryKey, string keyExtension)
where TGrainInterface : IGrain
{
throw new NotSupportedException();
}
public TGrainInterface GetGrain<TGrainInterface>(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();
}
}

25
plugins/Inventories/OrleansGrains/test/EasyAbp.EShop.Products.OrleansGrainsInventory.Domain.Tests/TestInventoryGrainProvider.cs

@ -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<IInventoryGrain> GetAsync(string grainKey)
{
return Task.FromResult(Grain ??= _serviceProvider.GetRequiredService<FakeInventoryGrain>());
}
}
Loading…
Cancel
Save