Question

In this documentation page it is adviced to use ensureInjected() per view/widgets:

The recommended pattern is to call ensureInjected() in the static initializer of your various widget types

But my use case is one shared .css file (and its corresponding CSSResource) among all views in application. Do I really have to call ensureInjected() for this CSSResource in all my views?

An alternative seems to be calling this method just in onModuleLoad() and than access the CSS resource from singleton. Is it legitimate approach? Does it it have any drawbacks?

Was it helpful?

Solution

What matters is that ensureInjected() is called at least once before you display anything referencing the CssResource, otherwise the stylesheet won't be present, and there would be no style to apply matching the class names.

So yes, it's OK to call ensureInjected() only once inonModuleLoad.

And you don't have to use a singleton, all instances of a given ClientBundle will share the same resource instances (they'll be generated as singletons).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top