Often there will be existing state (e.g. configuration) when starting embedded Weld. There should be an easy way to register a producer for this state. It is currently possible to add an extension and register a producer using the new BeanBuilder API but it requires a lot of boilerplate code. Ideally, we could support something like:
final Client client = new JerseyClientBuilder(env).using(conf.getJerseyClientConfiguration()).build(getName());
|
|
Weld builder = new Weld().disableDiscovery().addPackage(false, Main.class);
|
builder.addBean().addType(Client.class).produceWith(() -> client).disposeWith(c -> c.close()).addQualifier(DefaultLiteral.INSTANCE)
|
WeldContainer weld = builder.initialize()
|
|