fix(ivy): call factory functions with correct type for derived classes (#30855)

In a derived service class with no decorator (and therefore no factory) of
its own, the factory function of the base class will be used instead.
Previously this logic had a bug where the factory function would be called
with no arguments, which would incorrectly create an instance of the base
class.

This commit adds logic to call the base class' factory and pass the type of
the derived class, which will correctly construct an instance of the
derived class using the base class' factory. A test is also added to verify
correctness of this behavior.

PR Close #30855
This commit is contained in:
Alex Rickabaugh
2019-06-04 13:54:57 -07:00
committed by Andrew Kushnir
parent 0ee09cdd7e
commit 7912db3829
2 changed files with 12 additions and 2 deletions

View File

@ -438,7 +438,7 @@ function getUndecoratedInjectableFactory(token: Function) {
// just instantiates the zero-arg constructor.
const inheritedInjectableDef = getInheritedInjectableDef(token);
if (inheritedInjectableDef !== null) {
return inheritedInjectableDef.factory;
return () => inheritedInjectableDef.factory(token as Type<any>);
} else {
return () => new (token as Type<any>)();
}