Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [config-dev] [External] : Re: Proposal for CDI integration
  • From: Dmitry Kornilov <dmitry.kornilov@xxxxxxxxxx>
  • Date: Mon, 5 Jul 2021 14:52:22 +0000
  • Accept-language: en-GB, ru-RU, en-US
  • Arc-authentication-results: i=1; 1; spf=pass; dmarc=pass action=none; dkim=pass; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed;; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=e3sdLwDey/+qlEIVDounxThcbwYaZorzw4Qmhkbyob4=; b=VZYe1agQodJfT/10cnTNaTSr8apYS7WP8zvgjVRG7BIrjr31vK0zKnOXTASD39FPRgCom6a5wYj4D75SHsaeQnaYmT+yQJc1HJTDDwl2245lZYFW6t/M52vDC52oE7/kmfFGzYFRGPLzg/+TWj1dK8ufZSVD0ocr0iY2oQnJqAYqDjQSVEkBjnX1eVVBoyotbZ1Yl4HRhJhl4+3Zc1KATrcS96ukXJreOm1Hy6KIxTaTvWx2l2ZWXtmUya3BnVN5zZAm9ZHkOzKqq2KJksAQYQ32q+Wk4z1UhTGLkvbIyRcS5cjx1+FDSxUFCbIisTAUbX4IwThKzWhudV9GbDsvRg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901;; cv=none; b=RLEPhT/RjsgV5gnUM63XPjSRBM3gQ0dWQxGM/QjXkxZ1aT141svb+ulOa4KG2p9koCHwMc8W6h3N8JAAm/yrKact48ItRrKwcfvS8yCb4jQ0ZvD1o5f922Ob5gGnSlRqD/LjROrh3wN0NPTj37W4zqSCtJ1zHZafecIzi8l0vjeV9sQ0KtQidRG06DYcBtFBUecwOjMicYPB5WXPvKbLeMr1YcmTlDH+5anSpcUeD/STrvxBNpnql7SkXlLd+XKqmu5U76Ek9yUQS7NGzBOuyzatY1wK0cP7xn/Ug/B15wODHSgl6zeU1sbRfq1gYOchyKrATSXx+UFZuk8+4GEofw==
  • Delivered-to: config-dev@xxxxxxxxxxx
  • List-archive: <>
  • List-help: <>
  • List-subscribe: <>, <>
  • List-unsubscribe: <>, <>
  • Thread-index: AQHXcYN2zkOD/e1Fnk2YyTCVUeoXA6s0dbBA
  • Thread-topic: [External] : Re: [config-dev] Proposal for CDI integration

Jakarta Config is a core spec and should not depend on any other specifications. I like David’s proposal. I don’t see that we need to add Config specific annotations to other specifications such as Common Annotations, @Inject or CDI. We should define them in Config spec, define what they do and ship them with Config API allowing any injection framework to implement them. I am not a big fun of reusing annotations, so I would possibly name them with Config prefix which makes it clear where it belongs.


-- Dmitry


From: config-dev <config-dev-bounces@xxxxxxxxxxx> On Behalf Of Emily Jiang
Sent: Monday, July 5, 2021 11:52 AM
To: Jakarta Config project developer discussions <config-dev@xxxxxxxxxxx>
Subject: [External] : Re: [config-dev] Proposal for CDI integration


Thank you David for the CDI integration proposal! It looks good to me as it moves the dependency from CDI to Injection. By the way, for anyone who was not on the call, the context is that we try to make Config not to depend on CDI so that CDI can use Config. MP Config has a tighter integration with CDI. With that design, there will be circular dependency between Config and CDI if CDI wants to use Config. Also with this design, there will be a migration path from MP Config to Jakarta Config, which is very important to the end users. I think with this approach, most scenarios can be satisfied, so CDI injection can come in a later release if needed.



Jakarta Config has different use cases from MP Config. If some features in MP Config works well to satisfy the use cases of Jakarta Config. It is a great plus to take MP Config based on the experience and feedback. There is no need to reinvent the wheels. However, if the feedback for some MP Config needs to improve, Jakarta Config can rework the design to improve the situation. Hope this helps!




On Fri, Jul 2, 2021 at 12:48 AM David Lloyd <david.lloyd@xxxxxxxxxx> wrote:

In our weekly calls we have agreed that there exists a potential
dependency problem between Jakarta Config and CDI, which (put simply)
amounts to Jakarta Config using CDI APIs while CDI depends on Jakarta
Config to configure itself.  Additionally, we generally agree that CDI
should not be required in order to use Jakarta Config, and
particularly should not be required in order to map configuration
groups.  This proposal will outline a way which allows CDI to be
optional to Jakarta Config, while still allowing the programmatic API
of Jakarta Config to support complex object mapping, and allowing for
a consistent and intuitive experience with and without CDI.

Please review the entire proposal and, when replying, limit quoting to
the specific points where you have questions or comments.

Part 1: Configuration-to-interface mapping

First, we would provide a configuration mapping mechanism to allow
mapping of multiple configuration properties to a single coalescing

The coalescing type should be defined as an interface.  This allows
for simple composability and reuse for common groups of properties,
and also simplifies the requirements on the user.

As an example, consider a simple "hello world" service with a
configuration like this:

    public interface HelloWorldConfiguration {
        String message();
        int repeat();

Jakarta Config would provide an API which will implicitly map a
hierarchical section of the input configuration on to the interface,
such that configuration properties correspond to interface methods.
In absence of any other explicit metadata, the name of the
configuration property to map would be derived from the name of the
corresponding interface method.  It was discussed that it could be
possible to let the user decide whether to give the typical "get"
prefix for the property or not, based on their preference.

Part 1.1: Annotation usage

Annotation usage should be optional to the maximum extent possible,
using sensible rules to extrapolate default metadata such as deriving
configuration property names from the interface name and its method
names.  This minimizes boilerplate.  That said, there are sometimes
cases where the defaults are unsatisfactory; for example, the user may
wish to have an element name which does not directly correspond to the
corresponding configuration property.  In this case, we could prefer
reusing annotations from Jakarta Dependency Injection.  For example:

    public interface MyProgramConfiguration {
        String theHelloWorldMessage();
        int theNumberOfRepititions();

Another option (in case the Jakarta injection spec is not usable for
this purpose for some reason) would be to introduce specific
annotations within Jakarta Config for this purpose.

Other examples may include annotations to specify conversion behavior,
default values, validation, optionality, etc.

We must not rely on CDI APIs or annotations, otherwise we compromise
the ability of CDI to use Jakarta Config APIs or annotations.

Part 2: Integration with CDI

Integration with CDI may be achieved through several possible
approaches, but they all should have in common that the unit of
configuration injection is the configuration interface.  The reasons
for this are manifold: the implementation becomes simpler, and we
clearly separate concerns between configuration and injection.

While it might seem that this would add unreasonable boilerplate for
simple cases, I would contend that this is simpler than what we have
today in MicroProfile Config; consider this example (using MP Config):

    public class MyBeanClass {
        public String foo;

        public int bar;

        // ...

The drawbacks of the approach are numerous: the user has to specify
the @Inject annotation in order to inform CDI of the injection, and
the @ConfigProperty annotation because the type of the field is not
sufficient to tell CDI what is being injected.

Now consider an approach like this:

    public interface MyConfig {
        String foo();
        String bar();

    public class MyBeanClass {
        MyConfig config;

All of the relevant configuration is grouped into one object which can
be passed to different program components at will.  Increasing the
number of configuration properties does not increase the complexity of
any consumer that does not care about them.  And CDI can correctly
identify a configuration interface thanks to a single identifying
annotation on the configuration interface.

Part 2.1: CDI/Configuration dependency solutions

Using this divided approach where configuration mapping is handled
solely by the Configuration implementation and injection is handled
solely by CDI, the integration layer for CDI should be fairly simple.
All injections of interface types which are annotated by the
configuration root annotation are handled as configuration, and that's
the only integration point.  The handling would amount to passing the
interface to the configuration API for mapping.  Thus the
CDI/Configuration integration could easily reside within CDI itself,
with little risk of problems, resolving any future potential
circularity between Jakarta Configuration and CDI.

- DML • he/him

config-dev mailing list
To unsubscribe from this list, visit



Back to the top