Scaldi: couldn't find bindings defined in typesafe config

410 Views Asked by At

Here is the issue. Let assume I have two mutable modules:

class DbModule extends Module {   bind[JdbcBackend#Database] toProvider
    inject[JdbcDriver].backend.Database.forURL(
      inject[String]("db.url"),
      inject[String]("db.username"),
      inject[String]("db.password"), null,
      inject[String]("db.driver")
    ) }

and here is the corresponding config:

resources/application.conf:

db {  url="postgres url"  username="db_user"  password="db_password"  driver="cc"  }

Somewhere in the code I do:

implicit val inj = TypesafeConfigInjector() :: new AppModule

However this injector gives the following exception:

caldi.InjectException: No binding found with following identifiers:  
* TypeTagIdentifier(String)   * StringIdentifier(db.url)
1

There are 1 best solutions below

0
On

The order in Scaldi is important: the binding is resolved from left to right.

The :: operator, as stated in the docs, composes two injectors by inverting the operands. Thus, in your case, AppModule is resolved first, hence it cannot find the config params injected.

To solve your problem, use the ++ operator to keep your injectors in order.

I hope this is helpful.