Skip to content

Commit

Permalink
Renamed injectable wrapper. Added minor changes for factory support.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjohnsonaz committed Apr 16, 2018
1 parent f4959a4 commit d512515
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/scripts/Decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ export function inject(type: Index) {
}

export function injectable<T extends IConstructor<any>>(Constructor: T): T {
class Wrapper extends Constructor {
class Injected extends Constructor {
constructor(...args: any[]) {
super(...ParameterInfo.getArgs(Constructor, args));
}
}

// Change Wrapper name to match Constructor
Object.defineProperty(Wrapper, 'name', {
Object.defineProperty(Injected, 'name', {
value: Constructor.name
});

return Wrapper;
return Injected;
}

export function factory<T extends IFactory<any>>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) {
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/InjectionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ export default class InjectionContext {
static inject<T>(constructor: IConstructor<T>): T {
return new constructor(...ParameterInfo.getArgs(constructor));
}

static injectFunction<T>(func: Function): T {
return func(...ParameterInfo.getArgs(func));
}
}
6 changes: 4 additions & 2 deletions src/scripts/Types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export enum InjectionBindingType {
value,
constructor
value = 'value',
constructor = 'constructor',
factory = 'factory'
}

export type Index = string | number | Symbol;

export type IConstructor<T> = new (...args: any[]) => T;
Expand Down

0 comments on commit d512515

Please sign in to comment.