© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
6 replies
Victor H

Configuration of Testcontainer, WebApplicationFactory and ConfigurationSource in ASP.NET Core.

Hi, I'm trying to figure out a nice approach to setup my tests. I am writing an application where I am using the the Options pattern in my
Program.cs
Program.cs
to setup some connections option:
// Program.cs
builder.Services.AddOptions<PostgreSqlConnectionOptions>().BindConfiguration("PostgreSqlConnectionOptions");
builder.Services.AddOptions<RabbitMqConnectionOptions>().BindConfiguration("RabbitMqConnectionOptions");
// Program.cs
builder.Services.AddOptions<PostgreSqlConnectionOptions>().BindConfiguration("PostgreSqlConnectionOptions");
builder.Services.AddOptions<RabbitMqConnectionOptions>().BindConfiguration("RabbitMqConnectionOptions");

where for instance:
// PostgreSqlConnectionOptions.cs
public class PostgreSqlConnectionOptions
{
    public required string Host { get; set; } = "localhost";
    public required string Database { get; set; } = "myDb";
    public required string Username { get; set; } = "username";
    public required string Password { get; set; } = "password";
    public required int Port { get; set; } = 5432;
}
// PostgreSqlConnectionOptions.cs
public class PostgreSqlConnectionOptions
{
    public required string Host { get; set; } = "localhost";
    public required string Database { get; set; } = "myDb";
    public required string Username { get; set; } = "username";
    public required string Password { get; set; } = "password";
    public required int Port { get; set; } = 5432;
}

In my tests where I am using
WebApplicationFactory
WebApplicationFactory
together with Testcontainers I want to improve my setup. Can you offer me any advice on how to improve my setup code (next message).
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Blazor webassembly app hosted ASP.NET Core 7 test with WebApplicationFactory
C#CC# / help
4y ago
Database In ASP.Net Core
C#CC# / help
14mo ago
❔ ASP.NET to .net Core
C#CC# / help
3y ago