private static void Main(string[] args) { //setup our DI var serviceProvider = new ServiceCollection() .AddSingleton <IIOService, ConsoleService>() .AddSingleton <ISongWriter, SongWriter>() .AddSingleton <IValidatorSettings, ValidatorSettings>() .AddSingleton <IValidator>(provider => { var settings = provider.GetService <IValidatorSettings>(); return(new Validator(settings)); }) .AddSingleton <IRhymeGenerator>(provider => { var ioService = provider.GetService <IIOService>(); var validator = provider.GetService <IValidator>(); var songWriter = provider.GetService <ISongWriter>(); return(new RhymeGenerator(ioService, validator, songWriter)); }) .BuildServiceProvider(); IRhymeGenerator rhymeGenerator = serviceProvider.GetService <IRhymeGenerator>(); rhymeGenerator.Run(); }
public RapGenerator(IRhymeGenerator rhymeGenerator) { m_RhymeGenerator = rhymeGenerator; // Load required data from files Templates = System.IO.File.ReadAllText(TemplatesPath).Split('\n').ToList(); Nouns = System.IO.File.ReadAllText(NounsPath).Split('\n').ToList(); Adjectives = System.IO.File.ReadAllText(AdjectivesPath).Split('\n').ToList(); Verbs = System.IO.File.ReadAllText(VerbsPath).Split('\n').ToList(); }
private void InitializeAndRunRhymeGenerator( string inputFilePath, string outputFilePath) { IIOService ioService = new ConsoleService(); _validatorMock = new Mock <IValidator>(); _validatorMock .Setup(v => v.ValidateVersesCount(It.IsAny <string>())) .Returns(true); _validatorMock .Setup(v => v.ValidateAnimalName(It.IsAny <string>())) .Returns(true); _validatorMock .Setup(v => v.ValidateAnimalSound(It.IsAny <string>())) .Returns(true); _songWriterMock = new Mock <ISongWriter>(); _songWriterMock .Setup(v => v.Compose(It.IsAny <IEnumerable <Animal> >())) .Returns("song goes here"); _rhymeGenerator = new RhymeGenerator( ioService, _validatorMock.Object, _songWriterMock.Object); using (StreamReader reader = new StreamReader(inputFilePath)) { using (StreamWriter writer = new StreamWriter(outputFilePath)) { ioService.SetIn(reader); ioService.SetOut(writer); _rhymeGenerator.Run(); } } }