简体   繁体   English

将 EVENT 范围的 bean 注入到 CONVERSATION/SESSION 范围的 bean 中是否更安全?

[英]Is it safer to inject an EVENT scoped bean into a CONVERSATION/SESSION scoped bean?

Is it safe to inject beans from narrower scope into a wide scoped bean?将较窄的 scope 中的 bean 注入到范围广泛的 bean 中是否安全?

Does Seam CDI take care of it to figure out current EVENT/REQUEST/PAGE context to do the right injection into SESSION/CONVERSATION bean. Seam CDI 是否会处理它以找出当前的 EVENT/REQUEST/PAGE 上下文以正确注入 SESSION/CONVERSATION bean。

My point is.我的观点是。 I don't want one page/even's objects getting mixed up with other page/event's data.我不希望一页/甚至对象与其他页面/事件的数据混淆。

I can always use Component.getInstance() within the method to make sure I get current event/page's beans anyway.我总是可以在方法中使用 Component.getInstance() 来确保我得到当前事件/页面的 bean。 But I would like to use @In(scope = ScopeType.EVENT) even for this.但我什至想使用@In(scope = ScopeType.EVENT)

Session and page scoped components are synchronized per default. Session 和页面范围的组件默认同步。 Therefore, it should be safe to inject an event-scoped component, such as EntityManager , into them.因此,将事件范围的组件(例如EntityManager )注入其中应该是安全的。 As it is synchronized, two request won't interfere with two different injected objects.由于它是同步的,因此两个请求不会干扰两个不同的注入对象。

To be completely sure, that you don't run into concurrency problems, I recommend that you don't inject these components but fetch them from the component repository:为了完全确定,您不会遇到并发问题,我建议您不要注入这些组件,而是从组件存储库中获取它们:

MyComponent myComponent = (MyComponent) Component.getInstance("myComponent");

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM