vue-di-container
Version:
Dependency injection container for Vue
31 lines (30 loc) • 918 B
JavaScript
import { decorator } from './util';
export const Inject = Object.assign((key) => {
return decorator({
ctorParameter: (cls, index) => {
if (Inject.metadata && key !== undefined) {
Inject.metadata.setParameterKey(cls, index, key);
Inject.hooks.forEach(hook => hook(cls));
}
},
property: (cls, name) => {
if (Inject.metadata && typeof name === 'string') {
Inject.metadata.setPropertyKey(cls, name, key || null);
Inject.hooks.forEach(hook => hook(cls));
}
},
else: () => {
throw new Error('Unsupported injection target');
},
});
}, {
metadata: undefined,
hooks: [],
});
export const Service = Object.assign(() => {
return decorator({
class: cls => Service.hooks.forEach(hook => hook(cls)),
});
}, {
hooks: [],
});