Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            IContainer container;

            try
            {
                Cmd.WriteHeader("Initialising...");

                var bootstrapper = new Bootstrapper(ConnectionString);

                container = IoC.HaveYouAnyIoC(bootstrapper);

                if (!bootstrapper.DatabaseExists()) bootstrapper.CreateDatabase();
            }
            catch (Exception ex)
            {
                Cmd.WriteException(ex);
                Cmd.Pause();
                throw;
            }

            var commands = container
                .Resolve<IEnumerable<ICliCommand>>()
                .ToArray();
            var quitCommand = commands.OfType<QuitCommand>().Single();

            CliAppLoop.StartAppLoop(commands, quitCommand);
        }
Ejemplo n.º 2
0
        public static IContainer HaveYouAnyIoC(Bootstrapper bootstrapper)
        {
            var builder = new ContainerBuilder();

            builder
                .RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .Where(x => x.IsAssignableTo<ICliCommand>())
                .As<ICliCommand>()
                .InstancePerDependency();
            builder
                .RegisterInstance(bootstrapper)
                .AsSelf();
            builder
                .Register(_ => new Session(bootstrapper.ConnectionString))
                .AsSelf();

            return builder.Build();
        }
 public RecreateDatabaseCommand(Bootstrapper bootstrapper)
 {
     _bootstrapper = bootstrapper;
 }