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
  • Main
  • Usage

Was this helpful?

  1. Mandarine Core
  2. Properties

The @Value Decorator

PreviousPropertiesNextComponents

Last updated 4 years ago

Was this helpful?

This article requires knowledge of

Main

The @Value decorator allows you to access properties from your properties.json in a programatic way, this means, by using the @Value decorator, you can interact with your configuration in your components or native classes.

Usage

Syntax:

@Value(propertyKey: string)
  • propertyKey

    • Key reference of your property. If nested, please separate by using dots (.)

Example:

// ./src/main/resources/properties.json

{
    "mandarine": {
        "hello-message": "Bonjour!"
    },
    "customKey": "Here goes my custom value"
}
import { Value } from "https://deno.land/x/mandarinets/mod.ts";

export class ValueDecoratorTest {

    @Value('customKey')
    public static customKey: string;
    
    @Value('mandarine.hello-message')
    public bonjour: string;

}

console.log(ValueDecoratorTest.customKey); // Here goes my custom value
console.log(new ValueDecoratorTest().bonjour); // Bonjour!

In the example above we can see how we are using @Value on top of two different class fields: one that is static, and one that is not. Although, it works for both.

In the example above, we can also see how we are using nested properties with the @Value decorator.

Properties