My custom "cdi" context is not getting applied/ called

120 Views Asked by At

I have a custom @InjectableContext which I register during my build step

    @BuildStep
    ContextConfiguratorBuildItem registerContext(ContextRegistrationPhaseBuildItem contextRegistrationPhase) {
        return new ContextConfiguratorBuildItem(
            contextRegistrationPhase.getContext().configure(TenantScoped.class).normal().contextClass(TenantScopeContext.class));
    }

    @BuildStep
    CustomScopeBuildItem customScope() {
        return new CustomScopeBuildItem(TenantScoped.class);
    }

The annotation looks like this

@NormalScope
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
public @interface TenantScoped {}

When I run a QuarkusUnitTest in my deployment module, the context seems to work and is beeing applied. The get(..) methods of the injectable context implementation are called.

When I add the extension to an actual application, it seems not to work anymore. With @TenantScope annotated beans are produced as regular @ApplicationScoped, with my custom injectable context completely skipped.

My test service looks like this:

@ApplicationScoped
public class Service {

    @Inject
    @Named("tenantLong")
    AtomicLong tenantScopedString;

    public void setLong(long number) {
        tenantScopedString.set(number);
    }

    public long getLong() {
        return tenantScopedString.get();
    }

    @TenantScoped
    @Named("tenantLong")
    @Produces
    AtomicLong tenantLong() {
        return new AtomicLong(-1);
    }
}

I had a look at the implementation of the io.quarkus.narayana.jta.runtime.context.TransactionContext which seems to be done exactly the same way. So apparently something must be wrong or missing with my implementation.

Is there any obvious mistake or is there a detail somewhere else which I might have missed?

EDIT The issue is the bean type which I am using here. Somehow when using a type like AtomicLong it does skip the context implementation. Pobably know more soon: https://github.com/quarkusio/quarkus/issues/33417

0

There are 0 best solutions below