Mirror of https://github.com/roostorg/coop github.com/roostorg/coop
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 29 lines 876 B view raw view rendered
1# Dependency Injection Container 2 3Coop uses [BottleJS](https://github.com/young-steveo/bottlejs) for dependency injection. 4 5## Why Dependency Injection? 6 7- Enables mocking services in tests (required for ESM modules) 8- Supports runtime injection based on environment or feature flags 9- Makes dependencies explicit in the source code 10 11## How It Works 12 13Services are registered by name in the container. Each name acts as an interface that can have different implementations: 14 15```ts 16// Register a service 17bottle.service('MyService', MyServiceImpl); 18 19// Inject into a class 20class ActionAPI { 21 constructor(private readonly myService: Dependencies['MyService']) {} 22} 23 24export default inject(['MyService'], ActionAPI); 25``` 26 27## Why BottleJS? 28 29BottleJS was chosen over alternatives like Inversify because it supports injecting functions and scalar values, not just class instances.