How do I register a binding with both delayed instantiation and as a singleton

62 views Asked by At

I am new to scaldi. I have a class being used in my cloud environment configuration where I want two things to happen.

bind [EnvironmentInfo] to new EnvironmentInfo initWith(_.init())

First, I want it to be a singleton. It retrieves the runtime information (Google AppEngine in this case) and it should do this once on instantiation. It seems like initWith is a good choice.

Next, I want instantiation to be delayed until first request. Following the execution path it is being instantiated well before the first call.

If I can get delayed instantiation, then initWith should move to the class constructor.

1

There are 1 answers

0
S. Hebert On BEST ANSWER

My answer ended up being simple. I abstracted the singleton "state" and accessed it as a 'lazy val ...'.