Recommended pattern for Scopes when using Spring or CDI for UI

Hi,

I was wondering if there is a best-practice or recommended approach when building a UI with dependency injection (either Spring or CDI).

Most of the apps I have done tend to use a ‘template’ which consists of the application frame, i.e. the header, one or two sidebars, a footer and a space for the dynamic page content to sit.

The template bit (and it’s injected dependencies - menubar, header or whatever) tends to be scoped as @UIScope. I then create ‘Views’ that use the template as a layout, such as

@Route(value = "content-one", layout = ApplicationTemplate.class)

and Scope these pages as prototype (Spring) but I am not convinced this is correct based on all the other examples I have seen. Most simple examples don’t use the scope at all (but then they don’t use layout templates either) which suggests all UI elements being singletons but then I fall into issues with views being built early and trying to connect to the current UI which doesn’t exist yet → UI.getCurrent() == null.

Does anyone have any advice or recommendations on what they use?

Thanks.