Quarkus / CDI和“ java config” DI定义 [英] Quarkus / CDI and "java config" DI definitions

查看:164
本文介绍了Quarkus / CDI和“ java config” DI定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始了夸夸其谈的概念证明。容器启动的时间真是太神奇了!

I just started a quarkus proof of concept. The containers-start time is amazing!

现在,我正在研究依赖注入部分。并找出选项。

Right now, I'm working on the Dependency Injection part. And figuring out the options.

https://quarkus.io/blog/quarkus-dependency-injection/

我的偏好是:

我更喜欢构造函数注入。 (一切正常)。

I prefer constructor injection. (This has been going ok).

我更喜欢 java config,因此我可以遵循 Composition Root模式,将所有应用程序依赖项注入放在一个公共位置。 (请参见 https://blog.ploeh.dk/2011/07/28/CompositionRoot /

I prefer "java config" so I can follow the "Composition Root" pattern of putting all my application dependency injections in a common place. (See https://blog.ploeh.dk/2011/07/28/CompositionRoot/ )

对于Spring DI,这是通过

With Spring DI, this is done with the


org.springframework.context.annotation.Configuration

org.springframework.context.annotation.Configuration

并在那里声明Bean。

and declaring the Beans there.

又是说,我不想在我的所有类中都放置 @ApplicationScoped注释。

Aka, I prefer not to place "@ApplicationScoped" annotations all over my classes.

CDI / Quarkus是否支持 java config模型?我问起quarkus的原因是,我读过quarkus的CDI实现有限。

Does CDI/Quarkus support a "java config" model? The reason I ask about quarkus is that I read quarkus has a limited CDI implementation.


//开始引用///我们的主要目标是实现与CDI兼容的超音速
面向构建时间的DI解决方案。这将使
用户可以继续在其应用程序中使用CDI,还可以利用
Quarkus的构建时优化。但是,ArC并不是经过TCK验证的完整CDI
实施-另请参阅支持的
功能列表和限制列表。//结束引号

//start quote//Our primary goal was to implement a supersonic build-time oriented DI solution compatible with CDI. This would allow users to continue using CDI in their applications but also leverage Quarkus build-time optimizations. However, ArC is not a full CDI implementation verified by the TCK - see also the list of supported features and the list of limitations.//end quote

所以我的问题不只是CDI问题。

So my question isn't a solely CDI question.

我尝试了不同的互联网搜索字词,但向我展示Spring链接。 :(

I've tried different internet search terms, but they keep showing me Spring links. :(

推荐答案

您应该创建一个CDI bean来生产您的bean,这是Spring称为Java的标准CDI方法。配置。

You should create a CDI bean that will produce your beans, this is the standard CDI approach to what Spring calls Java Configuration.

所以像这样

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;


@ApplicationScoped
public class MyConfiguration {
    @Produces
    public MyBean myBean(){
        return new MyBean();
    }
}

这篇关于Quarkus / CDI和“ java config” DI定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆