简体   繁体   English

使用Weld SE(CDI)异步创建bean的正确方法是什么?

[英]What is the proper way to create a bean asynchronously using Weld SE (CDI)?

I am using a Weld SE container in my JavaFX application (via AfterburnerFX actually). 我在JavaFX应用程序中使用了Weld SE容器(实际上是通过AfterburnerFX)。 A component is initialized (when a dialog window is shown to the user) and it's fields are injected. 组件被初始化(当向用户显示对话框窗口时),并且其字段被注入。 However, creating one of its dependencies takes much time. 但是,创建其依赖项之一会花费很多时间。

Is there an available facility to instantiate a bean asynchronously directly in Weld SE? 是否有可用的工具直接在Weld SE中异步实例化bean? If not, what's a common design pattern to handle this? 如果没有,处理此问题的常见设计模式是什么?

If you want to control instantiation programmatically, you can inject a Provider for your component instead: 如果要以编程方式控制实例化,则可以为组件注入Provider

//Instead of
@Inject MyComponent comp;

// do this:
@Inject Provider<MyComponent> compProvider;

// Usage in code at any given time:
MyComponent comp = compProvider.get();

Note that you will probably get to the alternative Instance instead of Provider at some time in the future (or a different answer) which is an extended interface implementing provider and some more useful functions. 请注意,您将来可能会选择替代Instance而不是Provider (或其他答案),这是实现提供者和一些更有用功能的扩展接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Producer方法时,CDI(Weld SE)不注入内部依赖项 - CDI (Weld SE) not injecting inner dependencies when using Producer method Activiti CDI / Weld SE / CDI单元 - Activiti CDI / Weld SE / CDI unit 使用weld-se-core 和weld-servlet-core 时CDI 停止工作? - CDI stops working when using weld-se-core and weld-servlet-core? 在 Java SE 上运行单元测试时使用带有 Weld 的 CDI 不满足的依赖关系 - Unsatisfied dependencies using CDI with Weld when running unit tests on Java SE 在Java SE中拥有CDI和JPA的最简单方法是什么? - What is the easiest way to have CDI and JPA in Java SE? 焊接CDI:使用@Alternative @Singleton - Weld CDI : Using @Alternative @Singleton Java SE中的焊接CDI:调用PreDestroy注释的方法为时过早? - Weld CDI in Java SE: PreDestroy annotated method called too early? 使用带有Gradle应用程序插件的weld-se时的Bean发现问题 - Bean discovery problems when using weld-se with Gradle application plugin 尝试运行焊接时出错应用程序 - 无法初始化焊接SE容器 - 未找到任何Bean存档 - Error when try run Weld Se Applicaton - Weld SE container cannot be initialized - no bean archives found CDI 2.0,Java SE-在焊缝阴影3.0.5中未调用条件观察器方法 - CDI 2.0, Java SE - conditional observer method not called in weld-se-shaded 3.0.5.Final
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM