Webstorm tells me I want import {tagProperty} from "inversify/dts/annotation/decorator_utils"; when I use tagProperty. Unfortunately it looks like when I go to run, typescript disagrees: Error: Cannot find module 'inversify/dts/annotation/decorator_utils'
Not sure how "public-facing" that module is, but I'm looking to do property/setter injection without annotations.
The import:
import { tagProperty } from "inversify/dts/annotation/decorator_utils
Doesn't work because you are tying to import a dts file.
You can try with:
import { tagProperty } from "inversify/lib/annotation/decorator_utils
But please keep in mind that the tagProperty is supposed to be private.
What is you use case? I don't think it is a good idea to make these methods public but if you have a strong use case I will be happy to change my mind.
My interest in this is to provide injection for an abstract class setter/property. This allows subclasses to have full control over the constructor.
I've manually set it up so that a set happens prior to lifecycle, but I thought it would be nice to wire this using DI as well.
Can decorate do the job?
decorate(injectable(), Ninja);
decorate(inject(TYPES.Katana), Ninja, 0);
decorate(inject(TYPES.Shuriken), Ninja, 1);
I think that would impose on implementers a convention in their constructors. Which might risk breaking the fun/easy factor. This is to ensure applications have access to their "context".
The context needs to be provided at some point to the app shortly after being instantiated. The context is singleton-esque. This might be a case where I'm already doing the right thing and the container need not be involved. I was just thinking that if I'm able to get every dependency an app would need bound, inversify could handle everything for me.
Here is the specific property I'm thinking about: https://github.com/atrauzzi/protoculture/blob/master/src/App/Base.ts#L12
So you need something like this but the base class will be abstract?
Yeah, the weapon property/setter there looks about right. And of course abstract base, without using annotations.
I will try to test this and if it is not possible using decorate I will expose the functions you need.