'Set configuration part in startup with static parameters not json file in .net core

I have this line of code in my test solution .

I want to config ravenoption in my test code.

public IHost host = null;
public IDocumentStore documentStore = null;
public TestHostBuilder()
{
    ConfigureServer(new TestServerOptions() {FrameworkVersion = null});
    documentStore = GetDocumentStore();
    Environment.SetEnvironmentVariable("TEST_ENV", "on");
    var hostBuilder = easy.api.Program.CreateHostBuilder(new string[0])
.ConfigureWebHost(webHostBuilder =>
{
    webHostBuilder.UseTestServer();
}).ConfigureAppConfiguration(config =>
{
   config.Configure<domain.Environments.RavenOptions>(new domain.Environments.RavenOptions() {PublicUrl=documentStore.Urls.ToString() });


})
.ConfigureServices(services =>
{

   services.AddScoped<ICurrentUserService, InitRequest>();
   services.AddScoped<ICacheStorage>(provider =>
   {
       return new Mock<ICacheStorage>().Object;
   });
   services.AddRavenDbAsyncSession(GetDocumentStore(new GetDocumentStoreOptions()));
   services.AddTransient<IAsyncDocumentSession>((c) =>
    {
        return documentStore.OpenAsyncSession();
    });

});

    host = hostBuilder.Start();

}

So in this line

config.Configure<domain.Environments.RavenOptions>(new domain.Environments.RavenOptions() {PublicUrl=documentStore.Urls.ToString() });

I get this error :

Severity Code Description Project File Line Suppression State
Error CS1929 'IConfigurationBuilder' does not contain a definition for 'Configure' and the best extension method overload



Solution 1:[1]

Finally I created an Ioption object and inject it to the application :

.ConfigureServices(services =>
        {
            domain.Environments.RavenOptions appSettings = new domain.Environments.RavenOptions()
            {
                PublicDbName = documentStore.Database,
                CertificateDirectory="",
                IsHttps=false,
                PublicUrl=documentStore.Identifier.Split("(").First(),
                TseDbName=documentStore.Database,
                ShardUrls=Enumerable.Repeat(documentStore.Identifier.Split("(").First(), 4).ToArray()
            };
            IOptions<domain.Environments.RavenOptions> options = Options.Create(appSettings);
                   services.AddScoped<IOptions<domain.Environments.RavenOptions>>((p) =>
            {
                return options;
            });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ehsan Akbar