Skip to content

postConstruct isn't called on abstract base class #1905

@viceice

Description

@viceice

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I've method mark with postConstruct on a base class which doesn't get called

Steps to reproduce

@injectable()
export abstract class BaseService {
  @postConstruct()
  protected async [Symbol('_construct')](): Promise<void> {
    // never called
    console.log("construct");
    await Promise.resolve();
  }
}

@injectable()
@injectFromHierarchy()
class RealService extends BaseService {
 // some more code     
}

const c = new Container({autobind:true));

await c.getAsync(RealService); // should log `construct`

Expected behavior

it should call decorated method

Possible solution

No response

Package version

7.9.1

Node.js version

v22.19.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Stack trace

No response

Other

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions