Since all existing recipes for providers create singletons, even factory, you can create your own injector, inherit all providers from component injector and use resolveAndInstantiate method to get new instances every time:
import { Component, Inject, Injector, ReflectiveInjector } from '@angular/core';
class P {
}
const ps = [];
class C {
constructor(@Inject(P) p) {
ps.push(p);
}
}
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css']
})
export class AppComponent {
name = 'Angular';
constructor(injector: Injector) {
const parent = ReflectiveInjector.resolveAndCreate([P], injector);
const child = parent.resolveAndCreateChild([C]);
const c1 = child.resolveAndInstantiate(C);
const c2 = child.resolveAndInstantiate(C);
console.log(c1 === c2); // false
console.log(ps[0] === ps[1]); // true
}
}
Here is the demo.
Also bear in mind that ReflectiveInjector
is deprecated in @5.x.x. And it seems that there's no alternative in the new StaticInjector. I reported an issue about that.