di.js icon indicating copy to clipboard operation
di.js copied to clipboard

Document TransientScope

Open OliverJAsh opened this issue 10 years ago • 2 comments

I've looked hard at some examples, but I'm struggling to understand what a TransientScope is.

Could we do with some documentation to cover this?

OliverJAsh avatar Nov 12 '14 14:11 OliverJAsh

From @EisenbergEffect's blog:

Instance Scope

In Angular 1.x, all instances in the DI container were singletons. This is the default for Angular 2.0 as well. In order to get different behavior you had to use Services, Providers, Constants, etc. That's some confusing stuff. Fortunately, the new DI has a new, more general and more powerful feature. It now has instance scope control. So, if you want the DI to always create a new instance of a class, every time you ask for one, you can just do this:

@TransientScope
export class MyClass { ... } 

Read more: http://eisenbergeffect.bluespire.com/all-about-angular-2-0/

safrazik avatar Nov 12 '14 15:11 safrazik

always create a new instance of a class

Perfect explanation. This could be added to https://github.com/angular/di.js/blob/master/docs/terminology.md, if the documentation was expanded.

OliverJAsh avatar Nov 12 '14 15:11 OliverJAsh