Question: HikariCP database connection pool used in Play 2.5 [supports Dropwizard Metrics](https://github.com/brettwooldridge/HikariCP/wiki/Dropwizard-Metrics). The recommended approach is to use `HikariConfig.setMetricRegistry(MetricRegistry)`, but Play does not seem to be using Dependency Injection for HikariConfig. Is there another option to set MetricRegistry on Play HikariCP?

Answer: 
You can access the HikaryDatasource using

```
@Singleton
class InitMetricRegistry @Inject () (@NamedDatabaseProvider("default") val defaultDB: Database){
  val ds: HikariDataSource = defaultDB.dataSource.asInstanceOf[HikariDataSource]
  ds.setMetricRegistry(???)
}

```

To initialize the metrics on startup use an eager binding
<https://www.playframework.com/documentation/2.5.x/ScalaDependencyInjection#Eager-bindings>
Solved this using the same approach mentioned by @JonasAnso. Here is the Java snippet.

```
public class AppInitProcessor {
    @Inject
    public AppInitProcessor(Database db, MetricRegistry metricRegistry) {
        if (db.getDataSource() instanceof HikariDataSource) {
            HikariDataSource dataSource = ((HikariDataSource) db.getDataSource());
            if (dataSource.getMetricRegistry() == null) {
                dataSource.setMetricRegistry(metricRegistry);
            }
        }
    }
}

```

AppInitProcessor is then bound as an eager singleton from custom Guice module.

```
MetricRegistry metrics = new MetricRegistry();
// configure MetricsRegistry ...
bind(MetricRegistry.class).toInstance(metrics);
// bind app startup
bind(AppInitProcessor.class).asEagerSingleton();

```