Comparing version 0.3.13 to 0.4.0
@@ -0,1 +1,2 @@ | ||
export { inject, lazyInject } from 'power-di/helper'; | ||
import { InstanceSource } from './getInstance'; | ||
@@ -27,17 +28,1 @@ /** | ||
export declare function application(keyType?: any): (target: any) => void; | ||
/** | ||
* lazy inject | ||
* This can new Class and inject app/ctx (need from ctx) | ||
* @export | ||
* @param {*} [classType] class or string | ||
* @returns void | ||
*/ | ||
export declare function lazyInject(classType?: any): any; | ||
/** | ||
* inject | ||
* This can new Class and inject app/ctx (need from ctx) | ||
* @export | ||
* @param {*} [classType] class or string | ||
* @returns void | ||
*/ | ||
export declare function inject(classType?: any): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const decorators_1 = require("power-di/lib/helper/decorators"); | ||
const helper_1 = require("power-di/helper"); | ||
const appctx_1 = require("./appctx"); | ||
const getInstance_1 = require("./getInstance"); | ||
var helper_1 = require("power-di/helper"); | ||
exports.inject = helper_1.inject; | ||
exports.lazyInject = helper_1.lazyInject; | ||
const typeLoader_1 = require("./typeLoader"); | ||
@@ -45,42 +44,1 @@ /** | ||
exports.application = application; | ||
/** | ||
* lazy inject | ||
* This can new Class and inject app/ctx (need from ctx) | ||
* @export | ||
* @param {*} [classType] class or string | ||
* @returns void | ||
*/ | ||
function lazyInject(classType) { | ||
return (target, key) => { | ||
helper_1.lazyInject(classType)(target, key); | ||
classType = decorators_1.getClsTypeByDecorator(classType, target, key); | ||
return { | ||
configurable: true, | ||
get: function () { | ||
const ctx = appctx_1.getCtx(this); | ||
let app = appctx_1.getApp(this); | ||
if (!app && ctx) { | ||
app = ctx.app; | ||
} | ||
const value = getInstance_1.getInstance(classType, app, ctx); | ||
Object.defineProperty(this, key, { | ||
configurable: true, | ||
value: value | ||
}); | ||
return value; | ||
} | ||
}; | ||
}; | ||
} | ||
exports.lazyInject = lazyInject; | ||
/** | ||
* inject | ||
* This can new Class and inject app/ctx (need from ctx) | ||
* @export | ||
* @param {*} [classType] class or string | ||
* @returns void | ||
*/ | ||
function inject(classType) { | ||
return lazyInject(classType); | ||
} | ||
exports.inject = inject; |
@@ -0,1 +1,2 @@ | ||
import { IocContext } from 'power-di'; | ||
export declare type InstanceSource = 'Context' | 'Application'; | ||
@@ -5,2 +6,3 @@ export declare type CreateInstanceHookFunction = (instance: any, app: any, ctx?: any) => any; | ||
export declare const contextTypeSymbol: unique symbol; | ||
export declare function injectInstance(ioc: IocContext, inst: any, app: any, ctx: any): void; | ||
export declare function getInstance<T = any>(clsType: any, app: any, ctx: any): T; |
@@ -13,2 +13,8 @@ "use strict"; | ||
exports.contextTypeSymbol = Symbol('contextType'); | ||
function injectInstance(ioc, inst, app, ctx) { | ||
ioc.inject(inst, (_globalType, typeCls) => { | ||
return getInstance(typeCls, app, ctx); | ||
}); | ||
} | ||
exports.injectInstance = injectInstance; | ||
function getInstance(clsType, app, ctx) { | ||
@@ -49,2 +55,3 @@ let ioc = undefined; | ||
app.iocContext.register(value, clsType); | ||
injectInstance(app.iocContext, value, app, ctx); | ||
} | ||
@@ -77,4 +84,5 @@ value = new Proxy(value, { | ||
ioc.register(value, clsType); | ||
injectInstance(ioc, value, app, ctx); | ||
return value; | ||
} | ||
exports.getInstance = getInstance; |
{ | ||
"name": "egg-aop", | ||
"version": "0.3.13", | ||
"version": "0.4.0", | ||
"description": "aop for egg.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15458
370