static void InitializeContainer(CommandLineParameters parameters) { var builder = new ContainerBuilder(); builder.RegisterType <StrPathCalculator>().As <IPathCalculator>().SingleInstance(); builder.RegisterType <ConsolePrinter>().As <IPrinter>().SingleInstance(); builder.Register( ctx => parameters.IsConsole() ? (IResultWriter)(new ConsoleWriter()) : (new FileWriter(parameters.ResultFile, ctx.Resolve <IPrinter>())) ).SingleInstance(); builder.Register( ctx => { IFileHandler result = null; IResultWriter writer = ctx.Resolve <IResultWriter>(); IPathCalculator calculator = ctx.Resolve <IPathCalculator>(); IPrinter printer = ctx.Resolve <IPrinter>(); switch (parameters.GetAction()) { case Core.Action.All: result = new SimpleFileHandler(printer); break; case Core.Action.Cs: result = new CsFileHandler(printer); break; case Core.Action.ReversedOne: result = new ReverseOneFileHandler(printer); break; case Core.Action.ReversedTwo: result = new ReverseTwoFileHandler(printer); break; default: throw new Exception($"Invalid action: [{parameters.ActionStr}]"); } return(result); } ).InstancePerLifetimeScope(); builder.Register <IDirectoryHandler>( ctx => new DirectoryHandler(parameters.StartDirectory, ctx.Resolve <IFileHandler>(), ctx.Resolve <IResultWriter>(), ctx.Resolve <IPathCalculator>(), ctx.Resolve <IPrinter>()) ).InstancePerLifetimeScope(); builder.RegisterType <Scanner>().As <IScanner>().InstancePerLifetimeScope(); _container = builder.Build(); }