File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -123,3 +123,29 @@ customization. If you want to customize your dependency injection context,
123123it is recommended to provide your own implementation of
124124` io.cucumber.core.backend.ObjectFactory ` and make it available through
125125SPI.
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+ ```
You can’t perform that action at this time.
0 commit comments