refactored di into more composable parts

This commit is contained in:
Boki 2025-06-22 21:47:39 -04:00
parent 177fe30586
commit 26ebc77fe6
22 changed files with 908 additions and 281 deletions

View file

@ -0,0 +1,27 @@
import { asClass, asFunction, asValue, type AwilixContainer } from 'awilix';
import { createCache, type CacheProvider } from '@stock-bot/cache';
import type { AppConfig } from '../config/schemas';
import type { ServiceDefinitions } from '../container/types';
export function registerCacheServices(
container: AwilixContainer<ServiceDefinitions>,
config: AppConfig
): void {
if (config.redis.enabled) {
container.register({
cache: asFunction(() => {
return createCache({
redisConfig: {
host: config.redis.host,
port: config.redis.port,
password: config.redis.password,
},
});
}).singleton(),
});
} else {
container.register({
cache: asValue(null),
});
}
}