Skip to content

Named Bean: General

Except for @Local, the classes decorated by the other decorator functions are named beans. Zova provides a naming convention for such beans, which can avoid naming conflicts and facilitate cross-module usage

In essence, we only need to define all named beans through a general decorator function @Bean. Other decorator functions are derived from @Bean to provide different default parameters


For example, to define a store bean userInfo, there are two ways:

export class StoreUserInfo {}
@Bean({ scene: 'store', name: 'userInfo', containerScope: 'app' })
export class StoreUserInfo {}
  • scene
    • Optional
    • Default: bean
    • Bean scene value, used to classify beans
  • name
    • Optional
    • Default: automatically resolved from class name
    • Bean name
  • containerScope
    • Optional
    • Default: ctx
    • When injecting this bean into other bean instances, if containerScope is not explicitly specified, the value specified here is used

Bean Identifier

In Zova, a module is a natural bundle boundary, and automatically bundled into an independent asynchronous chunk when building

Therefore, when using named bean cross-module, we do not recommend injecting directly based on type, but rather on identifier

The system will automatically assign an identifier to each named bean as the following format:


For example, the previously created store bean userInfo corresponds to the identifier, where a-demo is the module name which userInfo belongs to

Decorator list

For ease of use and to simplify the code, Zova provides several derived named beans:

NameDescriptionscenedefault containerScope
@BeanGeneral decoratorbeanctx
@ModelModel: Unified Data Sourcemodelctx
@StoreGlobal state objectstoreapp
@StyleGlobal stylestyleapp
@ToolTool Beantoolapp

Released under the MIT License.