Example #1
0
 public static IServiceCollection AddApp(this IServiceCollection services)
 {
     return(services
            .AddSingleton <IStartup, ST.Startup>()
            .AddSingleton <MainForm>()
            .AddSingleton <IAppConfiguration, AppConfiguration>()
            .AddSingleton <IRepoHolder, RepoHolder>()
            .AddSingleton <IGitFileRepo, GitFileRepo>()
            .AddSingleton <IProjectFileRepo, ProjectFileRepo>()
            .AddSingleton <ITabsRepoBuilder, TabsRepoBuilder>()
            .AddSingleton <IAppSemaphoreSlim, AppSemaphoreSlim>()
            .AddSingleton <IGitVersion, RepoCommandProcessor>()
            .AddSingleton <ILoggerFactory>(sp =>
     {
         var eventSetting = new EventLogSettings
         {
             Filter = (msg, level) => level > LogLevel.Debug,
             SourceName = "GitLooker"
         };
         var provider = new EventLogLoggerProvider(eventSetting);
         return new LoggerFactory(new[] { provider });
     })
            .AddLogging()
            .AddSingleton(typeof(ILogger <>), typeof(Logger <>))
            .AddSingleton <IGitValidator, GitValidator>()
            .AddTransient <IProcessShell, ProcessShell>()
            .AddTransient <IRepoCommandProcessor, RepoCommandProcessor>()
            .AddTransient <RepoCommandProcessorController>()
            .AddTransient <SemaphoreInteractionInterceptor>()
            .AddTransient <TabReposControl>()
            .AddTransient(service =>
     {
         var myInterceptedClass = service.GetService <RepoCommandProcessorController>();
         var interceptor = service.GetService <SemaphoreInteractionInterceptor>();
         var proxy = new ProxyGenerator();
         return proxy.CreateInterfaceProxyWithTargetInterface <IRepoCommandProcessorController>(myInterceptedClass, interceptor);
     })
            .AddTransient <RepoControl>());
 }
Example #2
0
        private static void ApplyCommonConfiguration(IConfigurationRoot configuration, EventLogLoggerProvider eventLogProvider = null)
        {
            // This is needed because we are trying to read the config file. At this point we don't have the config info for the logger
            // we generally use in the broker. Log will be visible if the user runs broker interactively for broker running locally. Log
            // will be added to windows event log for the remote broker.
            using (ILoggerFactory configLoggerFactory = new LoggerFactory()) {
                configLoggerFactory
                .AddDebug()
                .AddConsole(LogLevel.Trace);

                if (eventLogProvider != null)
                {
                    configLoggerFactory.AddProvider(eventLogProvider);
                }

                ILogger logger = configLoggerFactory.CreateLogger <BrokerService>();
                try {
                    string configFile = configuration["config"];
                    if (configFile != null)
                    {
                        var configBuilder = new ConfigurationBuilder().AddJsonFile(configFile, optional: false);
                        configuration = configBuilder.Build();
                    }

                    Configuration = configuration;
                    Configuration.GetSection("startup").Bind(_startupOptions);
                    Configuration.GetSection("security").Bind(_securityOptions);
                    Configuration.GetSection("logging").Bind(_loggingOptions);
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    logger.LogCritical(Resources.Error_ConfigFailed, ex.Message);
                    Exit((int)BrokerExitCodes.BadConfigFile, Resources.Error_ConfigFailed, ex.Message);
                }
            }
        }