1

When looking through the main app bootstrapper, the InjectionProxy is used to register instances and interfaces. I noticed that interfaces can be registered as InstanceType.SingleInstance (done for the database in the Tesla app) or InstanceType.EachResolve. Further delving of the InjectionProxy code shows that instances are always SingleInstance.

What is the difference between SingleInstance and EachResolve, why would I choose my interfaces to be one or the other, and why are instances always set to be SingleIstance?

Timothy James
  • 1,062
  • 13
  • 25

1 Answers1

1

SingleInstance means that it will only ever create one copy of the class, for use in anything that requests it.

EachResolve, means that each class that has this interface injected into it, will get a new instance of the interface.

It depends on what you want for your app. In most cases, SingleInstance is what you want, but EachResolve is there incase your situation requires a new instance, instead of the same one used throughout your app.

Adam
  • 16,089
  • 6
  • 66
  • 109