fix: Autowired Java class error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-10-02 18:48:37 +08:00
parent 0fea6b5537
commit c7079dd82e
2 changed files with 4 additions and 2 deletions

View File

@ -62,14 +62,15 @@ export const JSClass = (className: string) => {
export const Autowired = (className?: any) => {
return function (target: any, propertyKey: string, index?: number) {
let container = getContainer()
if (className instanceof Symbol || className instanceof Function) {
if (className && (className instanceof Symbol || className instanceof Function)) {
return inject(className)(target, propertyKey, index)
}
let type = Reflect.getMetadata('design:type', target, propertyKey)
if (type && type !== Object) {
if (type && type !== Object && Java.isJavaObject(type)) {
inject(type)(target, propertyKey, index)
named(className || propertyKey)(target, propertyKey, index)
} else if (container.isBound(ioc.Autowired)) {
console.debug('Autowired', 'ioc.Autowired', 'named', className || propertyKey)
target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey)
} else {
throw new Error(`No matching bindings found for target: ${target.constructor.name} type: ${type} named: ${className || propertyKey}`)

View File

@ -17,6 +17,7 @@ declare global {
function to<T = any>(array: T[], type?: T): T[]
function extend(...parentTypes: any[]): any
function synchronized(func: () => void, lock: any): Function
function isJavaObject(obj: any): boolean
function asJSONCompatible<T = any>(obj: T): T
//@ts-ignore
// function super(type: any);