pleerock/routing-controllers-koa-demo

Request: example for running this with Inversify

blai opened this issue · 2 comments

blai commented

I see that the example works with typedi, but I also want to explore how this could work with Inversify. I tried a simple setup and could not get it to work, do I need to call useContainer?

Im not familiar with Inversify, but Im sure you can easily integrate it with it. useContainer accepts any thing that has a get method, or you can supply a proxy object to it which has get method. As I can see from inversify docs I can think that maybe you need to pass a kernel to useContainer?:

useContainer(kernel);

but Im not sure, you need to investigate inversify to figure it out

I got it workign with iversify 1.3.1. As @pleerock suggested I needed to wrap the Kernel with something that exposes a "get" method:


export class WrappedContainer {

    constructor(private injector : Kernel) {

    }

    get<T>(someClass : any) : T {
        return this.injector.resolve<T>(someClass.name);
    }

}

I also needed to use tell routing controllers to fallback on its own container, as certain types are not registered in my custom container: (MetadataArgsStorage)

useContainer(wrappedContainer, { fallback: true, fallbackOnErrors: true});