Skip to content

Add constructorCallback to generated micro package init - #551

Open
AzazelSensei wants to merge 1 commit into
Milad-Akarie:masterfrom
AzazelSensei:fix/492-micro-constructor-callback
Open

AzazelSensei wants to merge 1 commit into
Milad-Akarie:masterfrom
AzazelSensei:fix/492-micro-constructor-callback

Conversation

@AzazelSensei

@AzazelSensei AzazelSensei commented Aug 13, 2026 •

Copy link
Copy Markdown

MicroPackageModule.init only takes GetItHelper. With usesConstructorCallback the generator still wrote constructorCallback, which does not compile.

Generated micro init now takes the same optional named parameter as $initGetIt and wraps registrations with it.

Fixes #492

@ryanhanks-bestow

Copy link
Copy Markdown

This syntax error only arises when usesConstructorCallback is set for the InjectableInit.microPackage constructor – is that correct?

The docs for this argument read:

feature flag to activate a 'constructor callback'. Setting this to 'true' will generate an additional parameter to '$initGetIt' - named "constructorCallback" - a function of signature "T constructorCallback(T)". Injectable will pass all injectable objects to this delegate at the time of their constructor/module-method invocation. defaults to false

usesConstructorCallback is only true for the case of a micro package, leaving the logic proposed here (usesConstructorCallback && !isMicroPackage) testing for a condition which will never exist. I'd call this less of a "fix" and more of a semi-permanent decommissioning. A proper fix should add the additional parameter to initGetIt so the builder output matches the intent of the feature flag as stated in the documentation.

Was this causing an issue for you that you're hoping to alleviate?

My advice would be to take a crack at fixing this in the proper fashion. Is that something you thinking you can work through? The code builders can be a bit intimidating at first – let me know if you get stuck or want to try for an actual fix but are unsure how to proceed.

MicroPackageModule.init only takes GetItHelper. With
usesConstructorCallback the generated body still referenced
constructorCallback. Add the same optional named parameter
on the generated override and wrap instances with it.

Fixes Milad-Akarie#492
@AzazelSensei
AzazelSensei force-pushed the fix/492-micro-constructor-callback branch from e6f5b76 to c028ad4 Compare August 14, 2026 10:17
@AzazelSensei AzazelSensei changed the title Do not emit constructorCallback in micro package modules Add constructorCallback to generated micro package init Aug 14, 2026
@AzazelSensei

Copy link
Copy Markdown
Author

You are right, skipping it just turned the flag off. Generated micro init now takes constructorCallback the same way $initGetIt does, and wraps the registrations with it.

@ryanhanks-bestow

Copy link
Copy Markdown

Nice work. Thanks for picking that up and taking it to the finish line.

@ryanhanks-bestow ryanhanks-bestow left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usesConstructorCallback: true on micro package produces compilation error

2 participants