public static int Run(IBootstrap bootstrap, string[] args) { try { ServiceProgram.Container = bootstrap.RegisterContainer(); ServiceProgram.logger = ServiceProgram.Container.GetInstance <ILogger>(); ServiceProgram.logger.InfoFormat("IOC boot strapped..."); var exceptionLogger = ServiceProgram.Container.GetInstance <IExceptionLogger>(); Thread.GetDomain().UnhandledException += (sender, eventArgs) => { var ex = (Exception)eventArgs.ExceptionObject; ServiceProgram.logger.ErrorFormat(ex, "An unhandled exception was encountered."); exceptionLogger.Log(ex); }; if (Environment.UserInteractive) { var parameter = string.Concat(args).ToLower(CultureInfo.InvariantCulture); switch (parameter) { case "--install": ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location }); break; case "--uninstall": ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location }); break; case "--help": ServiceProgram.ShowHelp(); break; default: ServiceProgram.RunAsConsole(ServiceProgram.Container.GetInstance <IService>()); break; } } else { var servicesToRun = new ServiceBase[] { ServiceProgram.Container.GetInstance <ServiceProxy>() }; ServiceProgram.logger.InfoFormat("Executing ServiceBase.Run..."); ServiceBase.Run(servicesToRun); } } catch (Exception ex) { ServiceProgram.logger.ErrorFormat(ex, "Exception encountered in Main, exiting..."); return(-1); } ServiceProgram.logger.InfoFormat("Cleanly exiting application."); return(0); }