Skip to content

Commit bb569b9

Browse files
committed
chore: Switch to content tabs
1 parent d0c849e commit bb569b9

File tree

2 files changed

+50
-52
lines changed

2 files changed

+50
-52
lines changed
Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Connection String Provider
22

3-
The Connection String Provider API provides a standardized way to access and manage connection information for Testcontainers modules. It allows developers to customize module-provided connection strings or add their own, and to access module-specific connection strings or endpoints (e.g., database connection strings, HTTP API base addresses) in a uniform way.
3+
The Connection String Provider API provides a standardized way to access and manage connection information for Testcontainers (modules). It allows developers to customize module-provided connection strings or add their own, and to access module-specific connection strings or endpoints (e.g., database connection strings, HTTP API base addresses) in a uniform way.
44

55
!!!note
66

7-
Testcontainers modules do not yet implement this feature. Developers can use the provider to define and manage their own connection strings or endpoints. Providers will be integrated by the modules in future releases.
7+
Testcontainers modules do not yet implement this feature. Developers can use the provider to define and manage their own connection strings or endpoints. Providers will be integrated by modules in future releases.
88

99
## Example
1010

@@ -27,52 +27,50 @@ var containerConnectionString = container.GetConnectionString(ConnectionMode.Con
2727

2828
## Implementing a custom provider
2929

30-
To create a custom provider, implement the generic interface: `IConnectionStringProvider<TContainer, TConfiguration>`.
31-
32-
### Example: Generic provider
33-
34-
```csharp
35-
public sealed class MyProvider1 : IConnectionStringProvider<IContainer, IContainerConfiguration>
36-
{
37-
public void Configure(IContainer container, IContainerConfiguration configuration)
38-
{
39-
// Initialize provider with container information.
40-
}
41-
42-
public string GetConnectionString(ConnectionMode connectionMode = ConnectionMode.Host)
43-
{
44-
// This method returns a default connection string. The connection mode argument
45-
// lets you choose between a host connection or a container-to-container connection.
46-
return "...";
47-
}
48-
49-
public string GetConnectionString(string name, ConnectionMode connectionMode = ConnectionMode.Host)
50-
{
51-
// This method returns a connection string for the given name. Useful for modules
52-
// with multiple endpoints (e.g., Azurite blob, queue, or table).
53-
return "...";
54-
}
55-
}
56-
```
57-
58-
### Example: Module provider
59-
60-
```csharp
61-
public sealed class MyProvider2 : IConnectionStringProvider<PostgreSqlContainer, PostgreSqlConfiguration>
62-
{
63-
public void Configure(PostgreSqlContainer container, PostgreSqlConfiguration configuration)
64-
{
65-
// Initialize provider with PostgreSQL-specific container information.
66-
}
67-
68-
public string GetConnectionString(ConnectionMode connectionMode = ConnectionMode.Host)
69-
{
70-
return "Host=localhost;Port=5432;...";
71-
}
72-
73-
public string GetConnectionString(string name, ConnectionMode connectionMode = ConnectionMode.Host)
74-
{
75-
return "Host=localhost;Port=5432;...;SSL Mode=Require";
76-
}
77-
}
78-
```
30+
To create a custom provider, implement the generic interface: `IConnectionStringProvider<TContainer, TConfiguration>`. The `Configure(TContainer, TConfiguration)` method is invoked after the container has successfully started, ensuring that all runtime-assigned values are available.
31+
32+
=== "Generic provider"
33+
```csharp
34+
public sealed class MyProvider1 : IConnectionStringProvider<IContainer, IContainerConfiguration>
35+
{
36+
public void Configure(IContainer container, IContainerConfiguration configuration)
37+
{
38+
// Initialize provider with container information.
39+
}
40+
41+
public string GetConnectionString(ConnectionMode connectionMode = ConnectionMode.Host)
42+
{
43+
// This method returns a default connection string. The connection mode argument
44+
// lets you choose between a host connection or a container-to-container connection.
45+
return "...";
46+
}
47+
48+
public string GetConnectionString(string name, ConnectionMode connectionMode = ConnectionMode.Host)
49+
{
50+
// This method returns a connection string for the given name. Useful for modules
51+
// with multiple endpoints (e.g., Azurite blob, queue, or table).
52+
return "...";
53+
}
54+
}
55+
```
56+
57+
=== "Module provider"
58+
```csharp
59+
public sealed class MyProvider2 : IConnectionStringProvider<PostgreSqlContainer, PostgreSqlConfiguration>
60+
{
61+
public void Configure(PostgreSqlContainer container, PostgreSqlConfiguration configuration)
62+
{
63+
// Initialize provider with PostgreSQL-specific container information.
64+
}
65+
66+
public string GetConnectionString(ConnectionMode connectionMode = ConnectionMode.Host)
67+
{
68+
return "Host=localhost;Port=5432;...";
69+
}
70+
71+
public string GetConnectionString(string name, ConnectionMode connectionMode = ConnectionMode.Host)
72+
{
73+
return "Host=localhost;Port=5432;...;SSL Mode=Require";
74+
}
75+
}
76+
```

src/Testcontainers/Configurations/Containers/ConnectionStringProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal sealed class ConnectionStringProvider<TContainerEntity, TConfigurationE
1010
private readonly IConnectionStringProvider<TContainerEntity, TConfigurationEntity> _connectionStringProvider;
1111

1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="ContainerConfiguration" /> class.
13+
/// Initializes a new instance of the <see cref="ConnectionStringProvider{TContainerEntity, TConfigurationEntity}" /> class.
1414
/// </summary>
1515
/// <param name="connectionStringProvider">The connection string provider.</param>
1616
public ConnectionStringProvider(IConnectionStringProvider<TContainerEntity, TConfigurationEntity> connectionStringProvider)

0 commit comments

Comments
 (0)