Factory resolver using parameter decoration

Hi all,

I’m having a hard time finding an example of a factory resolver using parameter decorators (in TypeScript). I can’t figure out how to declare the resolver, nor how to use it! Something like constructor(@factory(SomeClass) someClassFactory: /* type? */) { ... }

This is what I have so far:

// the factory
@inject(BindingEngine, EventAggregator)
export class SomeClass {
        private readonly bindingEngine: BindingEngine,
        private readonly eventAggregator: EventAggregator,
        private readonly foo: /* some custom dependency */) { }

        publicMethod() { ... }

// the consumer
@autoinject() // not sure if I can do this?
export class SomeCustomElement {
    constructor(@factory(SomeClass) private readonly someClassFactory: /* what type? */) { }

    bind() {
        var foo = { /* localised dependencies */ };
        var someClassInstance: SomeClass = this.someClassFactory(foo);
        // then I want to:

I can use @inject(Factory.of(SomeClass)) but I’d like to try the parameter decorator as well.


I’m still looking for a solution to this :confused:

The documentation doesn’t provide any factory examples.

I can’t use new fooFactory() as in this bug report because I get a TypeError: this.fooFactoryis not a constructor.

I think it was added in this PR but I can’t figure out the code. I even had a look at the unit tests, but can’t figure out how to apply that to an actual decorator…

I can use the @inject(Factory.of(FooService)) but I sure would like to figure out parameter decoration as well…