Mandarine.TS
Latest
Latest
  • Mandarine.TS
  • Getting started
    • Installing Deno Runtime
    • Setting up Environment
    • Quick Example
  • Concepts
  • Mandarine Project Structure
  • Mandarine CLI
    • CLI Reference
      • mandarine new
      • mandarine generate
      • mandarine run
  • Mandarine Core
    • Core Initialization
    • Mandarine.json
    • Dot env file
    • Properties
      • The @Value Decorator
    • Components
      • Controller
      • Middleware
      • Repository
      • Component
      • Service
      • Configuration
      • Manual Component
    • Dependency Injection
      • Accessing DI container
    • Resource Handlers
      • Resource Handler Registry
      • Resource Handler
      • Resource Resolver
  • Mandarine MVC
    • Web MVC
    • Controllers
      • Routes
        • Parameterized Routes
      • HTTP Handlers
      • @ResponseStatus
    • Custom Middleware
    • Session Middleware
    • CORS Middleware
    • Template Engine
      • @Render Decorator
      • Accessing data from template
    • Launching web-app
    • Serving Static Content
    • Multipart Form Data
  • Mandarine Security
    • Sessions
  • Mandarine Data
    • ORM
      • Data source
      • Models
      • Repositories
        • Interacting with data
        • Updating data
    • Mandarine Query Language
  • Resources
    • Changelog
  • Plugins
    • Optional
    • Promise Repeater
Powered by GitBook
On this page
  • Concepts
  • Usage

Was this helpful?

  1. Mandarine Core
  2. Components

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

The @Injectable decorator handles the creation & representation of a non-native mandarine class inside the DI container. This means, @Injectable creates a manual component under the hood.

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".

PreviousConfigurationNextDependency Injection

Last updated 4 years ago

Was this helpful?