CDI: Why do I need a RouteScopeOwner?

Hi,

we have been using the CDI add-on happily for years with Vaadin 8. Especially the ability to use @ViewScoped beans anywhere was really helpful.

Now we are trying to move to Vaadin 14 and it seems that @(Normal)RouteScoped is not equivalent to @ViewScoped because I am forced to provide a @RouteScopeOwner.

Thing is: I absolutely do not want to hard-wire such beans to a specific route. In many cases I simply cannot do this, because the route/view is unknown. In other cases, I wouldn’t want to do this because it contradicts the concept of loose coupling.

I hope that I missed something obvious. Any help would be greatly appreciated.

@RouteScopeOwner is needed because in Router concept unlike in old Vaadin 8 Navigator, there can be multiple RouterLayouts, e.g. to achieve multi-tier navigation. Hence @RouteScoped bean needs to be mapped which RouterLayout actually defines the scope. In most apps you have only one, so this may sound a bit extra from that perspective.

Hi Tatu,

thank your for your explanation. We might be able to use the UI Scope instead in those cases where the RouterLayout is not known. Are there (in the UI Scope) any differences to Vaadin 8 that should be considered?