Creating services
Learn how to define and register services with Aurelia's dependency injection container.
Overview
Using DI.createInterface() to Create Injectable Services
DI.createInterface() to Create Injectable ServicesCreating an Interface Token with a Default Implementation
import { DI } from '@aurelia/kernel';
export class LoggerService {
log(message: string) {
console.log(message);
}
}
export const ILoggerService = DI.createInterface<ILoggerService>('ILoggerService', x => x.singleton(LoggerService));
// Export type equal to the class to create an interface
export type ILoggerService = LoggerService;Creating an Interface Token Without a Default Implementation
Exporting Classes Directly for Injectable Services
Simple Class Export
Decorator-based Registration
Exporting a Type Equal to the Class
Conclusion
Last updated
Was this helpful?