You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1020 B
31 lines
1020 B
using Kean.Domain.Stock.Enums;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Domain.Stock.Strategies
|
|
{
|
|
/// <summary>
|
|
/// 库存状态判定策略上下文
|
|
/// </summary>
|
|
public sealed class StateContext<T> where T : StateStrategy
|
|
{
|
|
private readonly T _strategy; // 策略实例
|
|
|
|
/// <summary>
|
|
/// 初始化 Kean.Domain.Stock.Strategies.StateContext 类的新实例
|
|
/// </summary>
|
|
public StateContext(IServiceProvider serviceProvider) =>
|
|
_strategy = Activator.CreateInstance(typeof(T),
|
|
typeof(T).GetConstructors().First().GetParameters().Select(p => serviceProvider.GetService(p.ParameterType)).ToArray()) as T;
|
|
|
|
|
|
/// <summary>
|
|
/// 判定库存状态
|
|
/// </summary>
|
|
/// <param name="barcode">托盘条码</param>
|
|
/// <returns>库存状态</returns>
|
|
public Task<CellState> GetState(string barcode) =>
|
|
_strategy.GetState(barcode);
|
|
}
|
|
}
|