开发者

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

开发者 https://www.devze.com 2023-03-20 16:50 出处:网络
Is it safe to inject beans from narrower scope into a wide scoped bean? Does Seam CDI take care of it to figure out current EVENT/REQUEST/PAGE context to do the right injection into SESSION/CONVERSAT

Is it safe to inject beans from narrower scope into a wide scoped 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.

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. But I would like to use @In(scope = ScopeType.EVENT)开发者_JS百科 even for this.


Session and page scoped components are synchronized per default. Therefore, it should be safe to inject an event-scoped component, such as EntityManager, into them. 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");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号