a library to speed up the development of Fivem scripts and frameworks
fivem-ts - Documentation v0.7.5 • Docs
fivem-ts - Documentation v0.7.5 / Server / Factory
Factory(
_target
,_propertyKey
,descriptor
):PropertyDescriptor
Factory decorator for methods that create instances and automatically register them as singletons in the DI container.
This decorator is used on methods that create instances of a class. When the method is called, the created instance is registered as a singleton in the DI container. This means that the same instance will be returned whenever the class is resolved from the container.
Example usage:
class MyService {
// Decorated factory method
@Factory
public static createInstance(): MyService {
return new MyService();
}
}
// Resolve the singleton instance
const myService = container.resolve(MyService);
• _target: unknown
The prototype of the class on which the method is defined. This parameter is not used.
• _propertyKey: string
The name of the method being decorated. This parameter is not used.
• descriptor: PropertyDescriptor
The property descriptor of the method being decorated.
PropertyDescriptor
The modified property descriptor with the factory logic applied.