Skip to content

fix: inject the right value in sub-class constructor paramsΒ #304

Open
@2betop

Description

@2betop

Description

please just see the code below.

Minimal code-snippet showcasing the problem

it('should inject the right value in subclass constructor params', function () {
    function CustomInject(value: any) {
      return function (target: Constructable<any>, propertyName: string, index: number) {
        Container.registerHandler({
          object: target,
          propertyName: propertyName,
          index: index,
          value: containerInstance => value,
        });
      };
    }

    @Service()
    class SuperService {
      constructor(@CustomInject(888) readonly num: number) {}
    }

    @Service()
    class SubService extends SuperService {
      constructor(@CustomInject(666) num: number) {
        super(num);
      }
    }

    expect(Container.get(SuperService).num).toBe(888);
    expect(Container.get(SubService).num).toBe(666);
  });

Expected behavior

expect(Container.get(SubService).num).toBe(666);

Actual behavior

the actual value is 888

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: fixedIssues with merged PRs, but not released yet.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions