Skip to content

Commit

Permalink
fix: Expose InjectWithMeta in DI during instantiate
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Malton <[email protected]>
  • Loading branch information
Nokel81 committed Jun 22, 2023
1 parent 4a9397f commit 816e57a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ const getInstance = ({
const minimalDi = {
inject: minimalInject,

injectWithMeta: (alias, parameter) =>
di.injectWithMeta(
alias,
parameter,
newContext,
injectableToBeInstantiated,
),

injectMany: (alias, parameter) =>
di.injectMany(alias, parameter, newContext, injectableToBeInstantiated),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,27 @@ describe('injection with meta data', () => {

expect(actual).toEqual([{ instance: 42, meta: { id: 'some-injectable' } }]);
});

it('given injectables, when injecting with meta with an injectable, works', () => {
const di = createContainer('some-container');

const someInjectable = getInjectable({
id: 'some-injectable',
instantiate: () => 42,
});

const someOtherInjectable = getInjectable({
id: 'some-other-injectable',
instantiate: di => di.injectWithMeta(someInjectable),
});

di.register(someInjectable, someOtherInjectable);

const actual = di.inject(someOtherInjectable);

expect(actual).toEqual({
instance: 42,
meta: { id: 'some-injectable' },
});
});
});

0 comments on commit 816e57a

Please sign in to comment.