Skip to content

Commit 65ec864

Browse files
raymondfengdhmlau
authored andcommitted
fix: honor service injection options
Fixes #8357 Signed-off-by: Raymond Feng <[email protected]>
1 parent cc05b13 commit 65ec864

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/core/src/__tests__/acceptance/service.acceptance.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import {Binding, Context} from '@loopback/context';
77
import {expect} from '@loopback/testlab';
8+
import {types} from 'util';
89
import {CoreTags, service} from '../..';
910
import {asService} from '../../service';
1011

@@ -73,6 +74,20 @@ describe('@service', () => {
7374
expect(controller.myService).to.be.undefined();
7475
});
7576

77+
it('allows asProxyWithInterceptors flag', async () => {
78+
class MyController {
79+
constructor(
80+
@service(MyService, {asProxyWithInterceptors: true})
81+
public myService?: MyService,
82+
) {}
83+
}
84+
85+
ctx.bind('controllers.MyController').toClass(MyController);
86+
87+
const controller = await ctx.get<MyController>('controllers.MyController');
88+
expect(types.isProxy(controller.myService)).to.be.true();
89+
});
90+
7691
it('allows serviceInterface as a string', async () => {
7792
class MyController {
7893
constructor(@service('MyService') public myService: MyService) {}

packages/core/src/service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ export function service(
109109
);
110110
}
111111
const view = new ContextView(ctx, filterByServiceInterface(serviceType));
112-
const result = view.resolve(session);
112+
const result = view.resolve({
113+
optional: metadata?.optional,
114+
asProxyWithInterceptors: metadata?.asProxyWithInterceptors,
115+
session,
116+
});
113117

114118
const serviceTypeName =
115119
typeof serviceType === 'string'

0 commit comments

Comments
 (0)