From 7f21fa67ee61d59be9d963f5f7b73c1909457a25 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Fri, 27 Sep 2019 18:39:40 +0800 Subject: [PATCH] feat: share decorators container Signed-off-by: MiaoWoo --- packages/container/src/decorators.ts | 4 ++-- packages/container/src/index.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/container/src/decorators.ts b/packages/container/src/decorators.ts index ad43e729..10217cd7 100644 --- a/packages/container/src/decorators.ts +++ b/packages/container/src/decorators.ts @@ -11,7 +11,7 @@ function _proxyGetter( resolve: () => any, doCache: boolean ) { - function getter() { + function getter(this: object) { if (doCache && !Reflect.hasMetadata(INJECTION, this, key)) { Reflect.defineMetadata(INJECTION, resolve(), this, key); } @@ -22,7 +22,7 @@ function _proxyGetter( } } - function setter(newVal: any) { + function setter(this: object, newVal: any) { Reflect.defineMetadata(INJECTION, newVal, this, key); } diff --git a/packages/container/src/index.ts b/packages/container/src/index.ts index 01f1b84c..235eeae2 100644 --- a/packages/container/src/index.ts +++ b/packages/container/src/index.ts @@ -1,4 +1,5 @@ import "reflect-metadata"; +import { initContainer } from './decorators' import { interfaces, Container } from 'inversify'; import { fluentProvide } from 'inversify-binding-decorators'; @@ -11,6 +12,7 @@ const provideSingleton = (identifier: interfaces.ServiceIdentifier) => { }; const DefaultContainer = new Container(); +initContainer(DefaultContainer); export * from 'inversify' export * from './decorators'