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

4.x: Config driven and pico @Named fixes #6674

Closed
tomas-langer opened this issue Apr 21, 2023 · 1 comment
Closed

4.x: Config driven and pico @Named fixes #6674

tomas-langer opened this issue Apr 21, 2023 · 1 comment
Assignees
Labels
4.x Version 4.x builder Related to the builder support declarative Helidon Declarative

Comments

@tomas-langer
Copy link
Member

The config driven should work as follows

configuration yaml:

server:
  port: 8080
ft:
  asyncs:
   first: 
    executor: "exec"
   second:
    executor: "service"
  bulkheads:
    - queue: 10

configuration beans:

@ConfigBean("ft.asyncs") // read it from ft.asyncs node, repeatable
AsyncConfig {..}

@ConfigBean("ft.bulheads") // read it from ft.bulkheads node, repeatable
BulkheadConfig {..}

@ConfigBean(value = "server", repeatable = false) // read it from server, not repeatable
ServerConfig {...}

When processing, the code to create the beans should be similar to this pseudo:

Config config; // located at the node of the config bean, such as `ft.asyncs`
if (configBeanAnnotation.repeatable()) {
  if (config.isList()) {
    - each node in the list is a config bean instance, named by the index (config.key().name()), we may want to introduce some custom config key to explicitly define a name, such as __name
  } else {
    - each child node is a config bean instance, named by the config node name (e.g. "first" and "second" for async)
    config.asNodeList().ifPresent(it -> it.forEach(configBeanCfg -> {
      String name = configBeanCfg.key().name(); // to be used with @Named
      String fullyQualifiedKey = configBeanCfg.key().toString(); // can also create a Named instance
  }
} else {
  // this is a non-repeatable config bean, just create a single instance from this place, not named (e.g. cannot be injected using @Named, as conceptually we cannot give it a name, we may support @default name + no name if we want to
}

To get instaces in Pico:

@Inject //config driven by ServerConfig
Server server;

@Inject //config driven by AsyncConfig
@Named("first")
Async firstAsync;

@Inject 
@Named("0") // index based naming - not much usable, but maybe somebody is just interested in the whole list and does not want to inject by name
Bulkhead bulkhead;
@trentjeff
Copy link
Member

After #6680 is merged, there will be this todo item:

    @Disabled("Will be addressed in #6674")
    @Test
    void namedConfiguredServices() {
        ConfigBeanRegistry cbr = (ConfigBeanRegistry) ConfigBeanRegistryHolder.configBeanRegistry().orElseThrow();
        Map<String, Collection<GeneratedConfigBean>> all = cbr.allConfigBeans();

//        System.out.println(all);
    }

In NamedConfiguredByTest.

trentjeff added a commit that referenced this issue Apr 25, 2023
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x builder Related to the builder support declarative Helidon Declarative
Projects
Archived in project
Development

No branches or pull requests

2 participants