Provide Decorator
This file defines the @Provide
decorator for marking classes as injectable providers in the @sodacore/di
dependency injection system. It attaches metadata to the class for use by the autowire module and DI logic.
Usage
typescript
import Provide from './provide';
@Provide()
export class MyService {}
@Provide('CustomService')
export class AnotherService {}
- Use
@Provide()
to register a class as a provider using its class name. - Use
@Provide('CustomName')
to register a class under a custom name.
API
Provide(name?: string): ClassDecorator
- Parameters:
name
(optional): The name to register the provider as. Defaults to the class name.
- Returns: A class decorator.
How It Works
- Sets the provider's name in the metadata (either the given name or the class name).
- Sets the provider's type as
'provider'
in the metadata. - The class will be initialized when the autowire module is called.
Notes
- This decorator only applies metadata; it does not instantiate or register the class by itself.
- Intended for use with the autowire and dependency injection system in
@sodacore/di
.