Skip to content

依赖node做组件的声明式注册 #43

Description

@otakustay

我们知道,在Spring中组件是可以声明式注册和注入的

@Service
public class Knife implements Weapon {
    // ...
}

public class Character {
    @Autowired
    public Knife setWeapon(Weapon weapon) {
        // ...
    }
}

但是JavaScript在前端环境中,由于并没有类似ClassLoader的机制在运行前扫描所有的组件,所以纯粹前端环境是无法做自动注入的(根本不知道有哪些组件存在)

但是如果我们在构建过程或者后端有一定的工作可以扫描所有的文件,显然可以做到声明式的配置,因此后续可以考虑这样的工具,作用是扫描所有的.js文件查找所有注册的组件和注入关系

这个工具可以在构建过程中用以自动生成IoC的配置对象,也可以运行在后端动态输出ioc-config.js之类的文件(甚至内联在HTML中)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions