andrade-soulseek-downloader
Version:
Simple, safe Soulseek download library with built-in rate limiting to prevent bans
72 lines • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DIContainer = void 0;
require("reflect-metadata");
const inversify_1 = require("inversify");
const domain_1 = require("../../domain");
const repositories_1 = require("../repositories");
const application_1 = require("../../application");
const services_1 = require("../services");
const youtube_downloader_1 = require("../services/youtube-downloader");
/**
* Dependency injection container using InversifyJS.
* Central configuration for all application dependencies.
*/
class DIContainer {
static container;
/**
* Gets singleton container instance.
* @returns Configured InversifyJS container
*/
static getContainer() {
if (!this.container) {
this.container = new inversify_1.Container();
this.configureDependencies();
}
return this.container;
}
/** Configures all application dependencies */
static configureDependencies() {
// Domain Services
this.container.bind('TrackSelectionService')
.to(domain_1.TrackSelectionService)
.inSingletonScope();
this.container.bind('DownloadRacingService')
.to(domain_1.DownloadRacingService)
.inSingletonScope();
// Application Use Cases
this.container.bind(application_1.DownloadTrackUseCase)
.toSelf()
.inTransientScope();
// Infrastructure Services
this.container.bind('ILogger')
.to(services_1.ConsoleLogger)
.inSingletonScope();
this.container.bind('IRateLimiter')
.to(services_1.RateLimiterAdapter)
.inSingletonScope();
this.container.bind('YouTubeDownloader')
.to(youtube_downloader_1.YouTubeDownloader)
.inSingletonScope();
// Repositories
this.container.bind('ITrackRepository')
.to(repositories_1.SoulseekTrackRepository)
.inSingletonScope();
}
/**
* Binds external Soulseek client instance.
* @param client - Soulseek client to inject
*/
static bindSoulseekClient(client) {
this.getContainer().bind('SoulseekClient').toConstantValue(client);
}
/** Resets container for testing */
static reset() {
if (this.container) {
this.container.unbindAll();
this.container = new inversify_1.Container();
}
}
}
exports.DIContainer = DIContainer;
//# sourceMappingURL=di-container.js.map