Skip to content

Singleton vs. Prototype Dependency Providers

brian428 edited this page Nov 14, 2012 · 5 revisions

Back to Advanced IoC Configuration

By default, the dependency providers set up with the DeftJS Injector are singletons. This means that only one instance of that dependency will be created, and the same instance will be injected into all objects that request that dependency.

For cases where this is not desired, you can create non-singleton (prototype) dependency providers like this:

Deft.Injector.configure({
  editHistory: {
    className: "MyApp.util.EditHistory",
    singleton: false
  }
});

So in this case, when a class specifies editHistory as an injection, DeftJS will create a new instance of EditHistory and inject it.

Next: Eager vs. Lazy Instantiation

Clone this wiki locally