Manual Component
This page summarizes the information & use of manual components.
Concepts
Manual components are not part of mandarine native components, instead, they are declared manually (usually in a configuration component) by the user.
After declaring a manual component, it will be added to the Dependency Injection Container and it will be available for injection across your mandarine-powered application.
They provide flexibility and adaptability for third-party libraries or existent codes.
Manual components are the way to declare an object that is not mandarine-powered injectable inside a mandarine-powered application.
Usage
Example
import { Configuration, Injectable, Component } from "https://deno.land/x/mandarinets/mod.ts";
export class ManualInjectionService {
public name: string;
constructor(name: string) {
this.name = name;
}
public helloWorld(): string {
return `Hello ${this.name}`;
}
}
@Configuration()
export class MainConfig {
@Injectable()
public ManualInjectionService() {
return new ManualInjectionService("Bill");
}
}
@Component()
export class MyComponent {
@Inject()
public service: ManualInjectionService;
public getResult(): string {
return this.service.helloWorld();
}
}
In the example above, we are injecting ManualInjectionService, even though it is not a valid mandarine component, we are making it valid & readable for the DI container by declaring it with @Injectable as shown above. This way, when we call MyComponent.getResult() we will get "Hello Bill".
Last updated
Was this helpful?