C# how can take parameters from BD before execute configureServices from Injection Dependecy

37 views Asked by At

In a .net 7.0. I need load some data before execute the configuration Services to Dependency Injection. ` private static IServiceProvider ConfigureServices(IConfiguration configuration) { var services = new ServiceCollection();

 string connectionString = configuration.GetConnectionString("sqlserver");
 string keyBd = StartupConfigurer.GetKeyApplication();
 string resultDEnc = StartupConfigurer.DecryptString(connectionString, keyBd);

 // Configurar los servicios necesarios
 services.AddSingleton<IDataConnection>(new DataConnection(resultDEnc))
         .AddSingleton<IExternalServiceClient, ExternalServiceClient>()
         .AddScoped(typeof(ISqlRepository<>), typeof(SqlRepository<>))
         .AddScoped(typeof(IDatabaseService<>), typeof(DatabaseService<>))
         .AddScoped<ISharedDataService, SharedDataService>()
         .AddSingleton(serviceLayer => new SLConnection(
                       "https://xxx.xxx.x.xx:xxxxx/b1s/v1/",
                       "TEST",
                       "HELLO",
                       "WORLD"))
         .AddScoped(typeof(IGenericRequestsS<>), typeof(GenericRequestsS<>))
         .AddScoped(typeof(IGenericRequestsC<>), typeof(GenericRequestsC<>))
         .AddScoped(typeof(IGenericRequestsG<>), typeof(GenericRequestsG<>));

 // AquĆ­ puedes configurar HttpClient manualmente
 services.AddSingleton<HttpClient>();

 return services.BuildServiceProvider();

}` I mean, on my database I've credentials that needs SLConnection and I want get this data before charge the method. Can I do this, or just save them in a file like the connectionString or KeyBd?

  • DataConnection save connectionString and open the connection.
  • SqlRepository has generic methods to execute any SQLSentences (CRUD).

Find a solution to GET Data from Database before load ConfigureService if is possible And respect Dependency Injection, or make alternatives.

0

There are 0 answers