Scaldi - default binding with override

78 views Asked by At

I would like to inject two different instances of my database wrapper class (DB): a default instance and a readonly instance.

99% of usages of the class use the default instance. I would therefore like to be able to use the simple inject[DB] to get the default instance.

For the readonly instance, I'd like to supply an override: inject[DB] identifiedBy 'readonly

I have setup my bindings as follows:

  bind[misc.DB] identifiedBy 'readonly to new misc.DB(..readonly params)
  bind[misc.DB] to new misc.DB(...readwrite params)

However, injecting the DB with the 'readonly identifier yields the readwrite instance. Is there any way to get this setup to work without having to supply an identifier for my default instance?

0

There are 0 answers