Skip to content

Commit

Permalink
feat(di): Added ability to override injectable property getter (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroslavAverianovAE authored May 5, 2021
1 parent 664970d commit ef16124
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
push:
pull_request:
branches:
- production
- 5.x

jobs:
test:
Expand Down
1 change: 1 addition & 0 deletions packages/di/src/interfaces/IInjectableProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IInjectablePropertyService extends IInjectableProperty {
bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;
propertyType: string;
useType: TokenProvider;
onGet?: (bean: any) => any;
options?: any;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/di/src/services/InjectorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export class InjectorService extends Container {
*/
public bindProperty(
instance: any,
{propertyKey, useType, options}: IInjectablePropertyService,
{propertyKey, useType, onGet = (f: any) => f, options}: IInjectablePropertyService,
locals: Map<TokenProvider, any>,
invokeOptions: Partial<IInvokeOptions>
) {
Expand All @@ -410,7 +410,7 @@ export class InjectorService extends Container {
locals.delete(DI_PARAM_OPTIONS);

Object.defineProperty(instance, propertyKey, {
get: () => bean
get: () => onGet(bean)
});
}

Expand Down

0 comments on commit ef16124

Please sign in to comment.