ferdinand-beyer / init

Dependency injection a la carte
MIT License
56 stars 0 forks source link

Configuration transformers #11

Open ferdinand-beyer opened 1 year ago

ferdinand-beyer commented 1 year ago

Many features that more complex DI frameworks provide can be done in init by simply transforming the configuration.

For example, consider Spring's @Conditional annotation, which will include beans only when certain conditions are met. Common examples are the presence of a certain class on the classpath (e.g. to auto-configure adapter beans) or beans of certain types (e.g. to provide defaults).

In init, we can simply discover the configuration, then remove components whose prerequisites are not met.

How do we configure such conditions? We can use tags, and/or add custom keys to components (components are just maps). When discovering components from vars, we can access the var's metadata.

How do we configure transformers? Since discovery + starting are two separate steps, we can transform the configuration before starting the system.

Explore:

This could be a convenient way for devs to pick the "features" they want, and be inspired to explore their own.

ferdinand-beyer commented 1 year ago

Maybe we can implement more of init's core with transformers as well:

By pulling this apart and being more modular, we enable use cases that we might not have thought of before!