Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: generate a custom constructor on a module class #143

Closed
mikehearn opened this issue Aug 3, 2021 · 2 comments
Closed

Idea: generate a custom constructor on a module class #143

mikehearn opened this issue Aug 3, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@mikehearn
Copy link

When a scope has external requirements, those objects must be provided via addBean before the scope can be built. Not doing so is an error. Without DI this error would be caught by the compiler, because you wouldn't be able to instantiate your target object at all unless you passed in what it needed, but with DI dependencies come from a dynamic map. It therefore seems to make sense if a module class had a constructor that required you to pass in these beans and automatically registered them.

@rbygrave
Copy link
Contributor

rbygrave commented Aug 5, 2021

Yeah, this is a good idea - I like it !!

@rbygrave
Copy link
Contributor

rbygrave commented Aug 6, 2021

So a note is that we still want 'default' scope modules to be service loaded (which means that they must have a default constructor).

This change this makes good sense for 'custom' scope modules. With custom scope modules they also won't ever really be service loaded. The only downside is we have this difference between custom modules and 'default' scope modules.

rbygrave added a commit that referenced this issue Aug 6, 2021
Now that custom modules can have no default constructor they can not be loaded via ServiceLoader. This should not matter as it really didn't make sense to service load the custom modules anyway.

Note that the 'default' scope modules still are expected to be service loaded. That does mean that we do not create a specific constructor for 'default' scope modules. External dependencies for default modules must still be provided via withBean()
@rbygrave rbygrave added this to the 6.7 milestone Aug 6, 2021
@rbygrave rbygrave closed this as completed Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants