chinto
chinto

Reputation: 1516

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?

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) even for this.

Upvotes: 2

Views: 558

Answers (1)

kraftan
kraftan

Reputation: 6312

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");

Upvotes: 1

Related Questions