Example #1
0
    public static void Main(string[] args)
    {
      ConfigureLog4net();
      WriteVanityBanner();

      using (MachineContainer container = new MachineContainer())
      {
        container.Initialize();
        container.PrepareForServices();
        ContainerRegistrationHelper helper = new ContainerRegistrationHelper(container);
        helper.AddServiceCollectionsFrom(typeof(PartstoreServices).Assembly);
        container.Start();
        IoC.Container = container;

        CommandLineParser parser = new CommandLineParser();
        parser.ParseCommandLine(args);

        string commandName = "help";
        if (parser.OrphanedArguments.Count > 0)
        {
          commandName = parser.OrphanedArguments[0].Value;
          parser.OrphanedArguments.RemoveAt(0);
        }

        CommandFactory commandFactory = new CommandFactory(container);
        commandFactory.AddCommand<ShowCommand>("show");
        commandFactory.AddCommand<UnpackageCommand>("unpackage");
        commandFactory.AddCommand<AddDependencyCommand>("add");
        commandFactory.AddCommand<AddNewVersionCommand>("publish");
        commandFactory.AddCommand<AddNewVersionCommand>("archive");
        commandFactory.AddCommand<SeachRepositoryCommand>("search");
        commandFactory.AddCommand<RefreshCommand>("refresh");
        commandFactory.AddCommand<ConfigureCommand>("config");
        commandFactory.AddCommand<HelpCommand>("help");
        ICommand command = commandFactory.CreateCommand(commandName);
        
        CommandLineOptionBinder bind = new CommandLineOptionBinder(parser, command);
        bind.Required<AddDependencyCommand>(x => x.ProjectName, bind.Named("project"), bind.Named("p"), bind.First());
        bind.Optional<AddDependencyCommand>(x => x.RepositoryName, bind.Named("repository"), bind.Named("r"));
        bind.Optional<AddNewVersionCommand>(x => x.RepositoryName, bind.Named("repository"), bind.Named("r"));
        bind.Optional<AddNewVersionCommand>(x => x.Tags, bind.Named("tags"), bind.Named("t"));

        if (bind.HasErrors)
        {
          foreach (BindingError error in bind.Errors)
          {
            Console.WriteLine(error);
          }
          return;
        }

        command.Run();

        Console.WriteLine();
      }
    }
        protected static IMachineContainer CreateContainer()
        {
            var container = new MachineContainer();
            ContainerRegistrationHelper helper = new ContainerRegistrationHelper(container);
            container.Initialize();
            container.PrepareForServices();
            helper.AddServiceCollection(new CoreServices());
            helper.AddServiceCollection(new SiteServices());
            helper.AddServiceCollection(new PersistenceServices());
            helper.AddServiceCollection(new MsMvcServices());
            helper.AddServiceCollection(new TeamManagementServices());
            container.Start();

            IoC.Container = container;
            var adapter = new CommonServiceLocatorAdapter(container);
            ServiceLocator.SetLocatorProvider(() => adapter);
            return container;
        }