Hey Gerhard,

thanks for the information. However, I now found a more suitable way for my requirements.

I have defined my own Qualifier

@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface TenantConfig {

    @Nonbinding
    String name();

    @Nonbinding
    String defaultValue() default ConfigProperty.NULL;

}

I am now extending the BaseConfigPropertyProducer to resolve properties that are annotated with the @TenantConfig

@ApplicationScoped
public class TenantConfigPropertyProducer extends BaseConfigPropertyProducer {

    // I can now use CDI and inject anything

    @Produces
    @Dependent
    @TenantConfig(name = "unused")
    public String produceStringProperty(InjectionPoint injectionPoint) {
      // Use Bean

    }

}

I am now annotating my properties with @TenantConfig rather than @ConfigProperty.

This works fine.

Thanks for the help.


Regards,

Kevin


Am 01.06.2016 um 19:23 schrieb Gerhard Petracek:
short addition:

you can have a look at an example at [1].

regards,
gerhard

[1]
http://cdiatwork.irian.at/book_de/introduction.html#!idx:/deltaspike.html:fig:db_aware_config-source

http://www.irian.at

Your JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German

Professional Support for Apache
MyFaces, DeltaSpike and OpenWebBeans

2016-06-01 19:10 GMT+02:00 Gerhard Petracek <[email protected]>:

hi kevin,

if the cdi-container isn't ready at the first access, you can just check
it via:

public String getPropertyValue(String key) {
   if (!BeanManagerProvider.isActive() || key.startsWith("deltaspike.")) {
     return null;
   }
   //...
}

you need to return null for those lookups and once the cdi-container is
ready, you can access your cdi-beans.
(skip keys used by deltaspike, if your config-source provides values for
your custom keys.)

regards,
gerhard

http://www.irian.at

Your JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German

Professional Support for Apache
MyFaces, DeltaSpike and OpenWebBeans



2016-06-01 17:50 GMT+02:00 Kevin Grüneberg <[email protected]>:

Hello,

is there any way to get CDI working in a ConfigSource?

Basically, I am trying to define a custom ConfigSource, that injects a
DAO to retreive the configuration parameters from a database. However, the
ConfigSource is registered via META-INF/Services and the class is loaded
very early, even before JNDI lookup or anything else works.

What I tried, for example, is something like

public class DatabaseConfigSource implements ConfigSource {

@Inject

private ConfigDao configDao;

public String getPropertyValue(String key) {

if (configDao == null) {

BeanProvider.injectFields(this);

}

}

}

I cannot call BeanProvider.injectFields(this), because the class is
instantiated so early, that there is no CDI context available.

Is there a way to get CDI to work for a custom ConfigSource?



Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to