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

API: make the VaultBuilder bean/injection-friendly #57

Open
eledhwen opened this issue Dec 11, 2022 · 0 comments
Open

API: make the VaultBuilder bean/injection-friendly #57

eledhwen opened this issue Dec 11, 2022 · 0 comments
Assignees

Comments

@eledhwen
Copy link
Contributor

eledhwen commented Dec 11, 2022

Current design relies a lot on the Vault class static methods as main entry points for building vaults.

While it is possible to work with differentiated VaultParser instances, the current API design does not make it clear nor easy. As a result, the path of least resistance systematically leads to the registration of custom modules directly into the default parser, eventually through static blocks, which is far from ideal.

Instead, we should make it possible for the user to be able to assemble a VaultBuilder providing the exact same facilities as the Vault static methods.

So just like we can currently do things like :

try (var vault = Vault.with(
  variables(defsdefs.set("some_var", 123)),
  "conf/first-conf.yml",
  "conf/second-conf.yml"
)) {
  SomeService s = vault.instance(SomeService.class);
}

where, prior to this if we need a custom module and/or preprocessor we have to do something like :

VaultFactory.defaultParser
  .register(new MyCustomModule())
  .registerPreprocessor(new MyCustomPreprocessor())
;

if one wants an injectable vault setting, it is already possible, but they have to write the following, which I find particularly impractical:

//this would be done in the setup phase somewhere
//requires knowledge of the inner workings (factory model, parser implementation)
var factory = new VaultFactory(new VaultCompositeParser()
    .register(new MyCustomModule())
    .registerPreprocessor(new MyCustomPreprocessor())
);

//verbose / unintuitive ; it does provide the tools for a multi-stage build however
var builder = Vault.builder()
    .setFactory(factory)
    .with(
        List.of(
            "conf/first-conf.yml",
            "conf/second-conf.yml"
        ),
        variables(defsdefs.set("some_var", 123))
    );

try (var vault = builder.build()) {
    SomeService s = vault.instance(SomeService.class);
}

instead, we could enable the following pattern :

/* Some place where core configuration logic happens */
VaultBuilder builder = Vault.builder(parserparser
  .register(new MyCustomModule())
  .registerPreprocessor(new MyCustomPreprocessor())
);

/* Someplace else where we need to load a configuration graph */
try (var vault = builder.with(
  variables(defsdefs.set("some_var", 123)),
  "conf/first-conf.yml",
  "conf/second-conf.yml"
)) {
  SomeService s = vault.instance(SomeService.class);
}
@eledhwen eledhwen self-assigned this Dec 11, 2022
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

When branches are created from issues, their pull requests are automatically linked.

1 participant