Introduction
We know that IOC(Inversion of Control) is an effective architectural design for system decoupling, and is also a supporting tool for the development of large-scale business systems
State Sharing: 4-in-1
In actual development, there are four scopes of state sharing: component internal, between components, global and system. In the traditional Vue3, different mechanisms are used to achieve these state sharing scopes, while only a unified IOC container mechanism is needed in Zova
| Scope of state sharing | Traditional Vue3 | Zova |
|---|---|---|
| Component internal | Composable | IOC |
| Between components | Provide/Inject | IOC |
| Global | Pinia | IOC |
| System | ES Module | IOC |
Some people may ask, what is the difference between
global state sharingandsystem state sharing?Because in SSR scenarios,
global state sharingis for each request, andsystem state sharingcan cross requests
IOC Containers
There are three types of ioc containers in Zova:
sys container: During system initialization, a unique sys ioc container will be automatically created. Bean instances created in this container are all singleton modeapp container: When requests coming, the system will create a app container for each of them. The Bean instances created in this container arerequest-scopedsingletonsctx container: When creating Vue component instances, the system will create a ctx ioc container for each of them. Bean instances created in this container can share data and logic within the scope of the component instance
Bean Class
Zova adopts a modular system, and Bean Classes are provided by different modules
Injection Scope
Zova provides the following injection scopes:
sys: Inject in the sys containerapp: Inject in the app containerctx: Inject in the ctx containernew: Always create a new bean instance
Injection Scope: Hierarchical injection
The injection scope also supports hierarchical injection, replacing the capabilities of Vue3 Provide/Inject:
host: the bean instance will be lookuped in the ctx container of the current component instance and all parent containers in turnskipSelf: lookup the bean instance in all parent containers in turn
Injection Methods
Zova provides two injection methods:
Dependency Injection: Provides property-based dependency injection through the@UsedecoratorDependency Lookup: Directly looks up the required bean instance through the ioc container, and automatically creates it if it does not exist