private static IHostBuilder CreateHostBuilder(string[] args) { return(Host.CreateDefaultBuilder(args) .ConfigureServices(services => { services.AddLogging(config => config.AddConsole()); services.AddTransient <Program>(); services.AddTransient <ServiceResolver>(); services.AddTransient <ServiceA>(); services.AddTransient <ServiceB>(); services.AddTransient <Func <string, IService> >(provider => key => { switch (key) { case "A": return provider.GetService <ServiceA>(); case "B": return provider.GetService <ServiceB>(); default: return provider.GetService <ServiceA>(); } }); }) .ConfigureAppConfiguration(config => { config.SetBasePath(Directory.GetCurrentDirectory()); config.AddJsonFile("Appsettings.json", true, true); })); }
private static void RegisterServices(IConfiguration config, IServiceCollection services) { services.AddLogging(config => { config.AddDebug(); // Log to debug (debug window in Visual Studio or any debugger attached) config.AddConsole(o => { o.IncludeScopes = false; o.DisableColors = false; }); // Log to console (colored !) }) .Configure <LoggerFilterOptions>(options => { options.AddFilter <DebugLoggerProvider>(null /* category*/, LogLevel.Trace /* min level */); options.AddFilter <ConsoleLoggerProvider>(null /* category*/, LogLevel.Trace /* min level */); // Comment this line to see all internal DEM.Net logs //options.AddFilter<ConsoleLoggerProvider>("DEM.Net", LogLevel.Information); }) .Configure <AppSecrets>(config.GetSection(nameof(AppSecrets))) .Configure <DEMNetOptions>(config.GetSection(nameof(DEMNetOptions))) .AddDemNetCore() .AddDemNetglTF(); RegisterSamples(services); }
/// <summary> /// Adds services required by the command line application to the service collection. /// </summary> /// <param name="services">The service collection to add to.</param> /// <param name="config">The <see cref="IConfiguration"/>.</param> /// <returns>The service collection, for chaining.</returns> public static IServiceCollection AddMarainServices(this IServiceCollection services, IConfiguration config) { services.AddLogging(config => config.AddConsole()); services.AddJsonNetSerializerSettingsProvider(); services.AddJsonNetPropertyBag(); services.AddJsonNetCultureInfoConverter(); services.AddJsonNetDateTimeOffsetToIso8601AndUnixTimeConverter(); services.AddSingleton <JsonConverter>(new StringEnumConverter(true)); var msiTokenSourceOptions = new AzureManagedIdentityTokenSourceOptions { AzureServicesAuthConnectionString = config["AzureServicesAuthConnectionString"], }; services.AddAzureManagedIdentityBasedTokenSource(msiTokenSourceOptions); TenancyClientOptions tenancyClientOptions = config.GetSection("TenancyClient").Get <TenancyClientOptions>(); services.AddSingleton(tenancyClientOptions); services.AddTenantProviderServiceClient(); services.AddMarainTenantManagement(); return(services); }
static void Main(string[] args) { config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .AddEnvironmentVariables() .Build(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <TelnetListener>(); serviceCollection.AddSingleton <IClusterClient>((service) => { var client = StartClientWithRetries().GetAwaiter().GetResult(); return(client); }); serviceCollection.AddLogging(config => { config.AddFilter((level) => { return(true); }); config.AddConsole(); }); var Container = serviceCollection.BuildServiceProvider(); var serviceScopeFactory = Container.GetRequiredService <IServiceScopeFactory>(); using (var scope = serviceScopeFactory.CreateScope()) { var telnetListener = scope.ServiceProvider.GetService <TelnetListener>(); telnetListener.OpenAsync(new CancellationToken()).GetAwaiter(); } appStopped.WaitOne(); }