[Enhancement]: Support ConfigurationProvider
(ASP.NET integration) together with modules
#1068
Labels
enhancement
New feature or request
Problem
There are several ways to integrate Testcontainers into ASP.NET (integration) tests. Developers often have to write the code to leverage Testcontainers into ASP.NET (integration) tests repeatedly.
Solution
To simplify the integration of dependent services into ASP.NET applications using Testcontainers, we can utilize Microsoft's
IConfigurationSource
interface and theConfigurationProvider
class. These allow us to initiate default module configurations and set up the actual ASP.NET application, making it straightforward for developers to incorporate Testcontainers into their ASP.NET integration tests and set up their ASP.NET configuration with the dependent services.The interesting part here is the
LoadAsync()
member that starts the dependent service and sets the connection string. The actual app can simply read the connection string as it usually does usingConfiguration.GetConnectionString("RedisCache")
.I am still considering the best place to implement and store the interface and class. Overall, I aim to avoid implementing them in every module and introducing extra dependencies like
Microsoft.Extensions.Configuration
to the modules.Benefit
Developers will be able to integrate Testcontainers into tests much more simply. Leveraging it into ASP.NET (integration) tests would only require a single line and makes the startup and teardown implementation obsolete.
Alternatives
-
Would you like to help contributing this enhancement?
Yes
The text was updated successfully, but these errors were encountered: