Skip to content

Commit 6853a30

Browse files
committed
add README description and example
1 parent a7dc4dd commit 6853a30

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cucumber-picocontainer/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,29 @@ customization. If you want to customize your dependency injection context,
123123
it is recommended to provide your own implementation of
124124
`io.cucumber.core.backend.ObjectFactory` and make it available through
125125
SPI.
126+
127+
However it is possible to configure additional PicoContainer `Provider`s and/or
128+
`ProviderAdapter`s. For example, some step definition classes might require a
129+
database connection as a constructor argument.
130+
131+
```java
132+
package com.example.app;
133+
134+
import java.sql.*;
135+
import io.cucumber.picocontainer.PicoConfiguration;
136+
import org.picocontainer.injectors.ProviderAdapter;
137+
138+
@PicoConfiguration(providerAdapters = { ExamplePicoConfiguration.DatabaseConnectionProvider.class })
139+
public class ExamplePicoConfiguration {
140+
141+
public static class DatabaseConnectionProvider extends ProviderAdapter {
142+
public Connection provide() throws ClassNotFoundException, ReflectiveOperationException, SQLException {
143+
// Connecting to MySQL Using the JDBC DriverManager Interface
144+
// https://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html
145+
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
146+
return DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "mydbuser", "mydbpassword");
147+
}
148+
}
149+
150+
}
151+
```

0 commit comments

Comments
 (0)