Skip to content

Commit

Permalink
fix(context): instantiate class with non-injected arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
psaunders authored and raymondfeng committed Apr 11, 2019
1 parent 7a372a8 commit 6699825
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/context/src/__tests__/unit/resolver.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ describe('constructor injection', () => {
expect(t.foo).to.eql('FOO');
});

it('allows non-injected arguments in constructor', () => {
class TestClass {
constructor(
@inject('foo') public foo: string,
public nonInjectedArg: string,
) {}
}

let theNonInjectedArg = 'BAZ';

const test = instantiateClass(TestClass, ctx, undefined, [
theNonInjectedArg,
]) as TestClass;
expect(test.foo).to.eql('FOO');
expect(test.nonInjectedArg).to.eql('BAZ');
});

it('can report error for missing binding key', () => {
class TestClass {
constructor(@inject('', {x: 'bar'}) public fooBar: string) {}
Expand Down
8 changes: 7 additions & 1 deletion packages/context/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ export function instantiateClass<T>(
debug('Non-injected arguments:', nonInjectedArgs);
}
}
const argsOrPromise = resolveInjectedArguments(ctor, '', ctx, session);
const argsOrPromise = resolveInjectedArguments(
ctor,
'',
ctx,
session,
nonInjectedArgs,
);
const propertiesOrPromise = resolveInjectedProperties(ctor, ctx, session);
const inst: ValueOrPromise<T> = transformValueOrPromise(
argsOrPromise,
Expand Down

0 comments on commit 6699825

Please sign in to comment.