public void Eat() { var human = provider.GetRequiredService <Human>(); var foodFactory = provider.GetRequiredService <IFoodFactory>(); string input = string.Empty; while (true) { try { ioService.Write("What type of food? "); input = ioService.Read(); logger.LogDebug("What type of food? {input}", input); human.EatFood(foodFactory.NewFood(input)); } catch (Exception ex) { logger.LogError($"There was a problem eating {input}", ex); } ioService.Write("Continue eating? "); string eatMore = ioService.Read(); if (eatMore?.Equals("n", StringComparison.InvariantCultureIgnoreCase) ?? false) { break; } } }