The implementation factory of the GetService() method can be used to determine the type of InventoryCommand class to be returned. For this example, a new static method is created in the InventoryCommand class:
public static Func<IServiceProvider, Func<string, InventoryCommand>> GetInventoryCommand => provider => input =>{ switch (input.ToLower()) { case "q": case "quit": return new QuitCommand(provider.GetService<IUserInterface>()); case "a": case "addinventory": return new AddInventoryCommand(provider.GetService<IUserInterface>(), provider.GetService<IInventoryWriteContext>()); case "g": case "getinventory": return new GetInventoryCommand(provider.GetService<IUserInterface>(), provider.GetService<IInventoryReadContext>()); ...