Skip to content

Commit

Permalink
fix: honor service injection options
Browse files Browse the repository at this point in the history
Fixes #8357

Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng authored and dhmlau committed Feb 28, 2022
1 parent cc05b13 commit 65ec864
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/core/src/__tests__/acceptance/service.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {Binding, Context} from '@loopback/context';
import {expect} from '@loopback/testlab';
import {types} from 'util';
import {CoreTags, service} from '../..';
import {asService} from '../../service';

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

it('allows asProxyWithInterceptors flag', async () => {
class MyController {
constructor(
@service(MyService, {asProxyWithInterceptors: true})
public myService?: MyService,
) {}
}

ctx.bind('controllers.MyController').toClass(MyController);

const controller = await ctx.get<MyController>('controllers.MyController');
expect(types.isProxy(controller.myService)).to.be.true();
});

it('allows serviceInterface as a string', async () => {
class MyController {
constructor(@service('MyService') public myService: MyService) {}
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export function service(
);
}
const view = new ContextView(ctx, filterByServiceInterface(serviceType));
const result = view.resolve(session);
const result = view.resolve({
optional: metadata?.optional,
asProxyWithInterceptors: metadata?.asProxyWithInterceptors,
session,
});

const serviceTypeName =
typeof serviceType === 'string'
Expand Down

0 comments on commit 65ec864

Please sign in to comment.