-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Problem with container auto-group/one-per-scope types #10222
Comments
Another alternative is to just have public tag interfaces that get implemented by these special types: type OnePerScopeType interface {
IsOnePerScopeType()
} This will allow structs or type aliases to be used without module developers needing to worry about a weird embedded struct field. I think I like this interface approach best. |
So if we wanted to provide a one-per-scope type we would need to impl this interface, same goes for auto-group. It's unfortunate, but probably it is the best. It will need proper documentation because it's something that can be easily over-looked. |
These need to be configured anyway though. Seems more fool-proof than the So I think unless there's any objections I'll go with the interface approach. Does that sound fine? |
Yeah @aaronc , I think is the best approach. |
Thanks for the input guys. Fixed in #9666 now. |
I have uncovered an issue with auto-group and one-per-scope types in the container API.
Basically, if you have a provider which provides auto-group or one-per-scope types, but these haven't been declared as auto-group or one-per-scope in the container yet we'll get an error. An example could be say we have an one-per-scope type
upgrade.Handler
. Many modules may provide this, but say we don't actually load the upgrade module which sets theOpenPerScope
option on the container. Then all these other modules will fail. (By the way, there is no clean way for the upgrade module to even set theOnePerScope
option if itsModule
is loaded from YAML)I see two solutions. One use tags like dig, i.e.
This has the overhead of needing to use tags everywhere and if we don't, the proper one-per-scope or auto-group behavior isn't followed in this instance and then we get an error.
An alternative would be marking the types at compile time with some sort of embedded struct, i.e.
I think this is maybe cleaner because it puts the burden on framework developers rather than module developers. One downside is we couldn't use this with type aliases, i.e. instead of
type QueryCommand *cobra.Command
, we'd need a struct like:Thoughts @jgimeno @fdymylja ?
The text was updated successfully, but these errors were encountered: