Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "typescript-ioc"

Index

Functions

AutoWired

  • AutoWired(target: Function): any
  • A decorator to tell the container that this class should its instantiation always handled by the Container.

    An AutoWired class will have its constructor overriden to always delegate its instantiation to the IoC Container. So, if you write:

    @ AutoWired
    class PersonService {
      @ Inject
      personDAO: PersonDAO;
    }
    

    Any PersonService instance will be created by the IoC Container, even when a direct call to its constructor is called:

    let PersonService = new PersonService(); // will be returned by Container, and all internal dependencies resolved.
    

    It is the same that use:

    Container.bind(PersonService);
    let personService: PersonService = Container.get(PersonService);
    

    Parameters

    • target: Function

    Returns any

Inject

  • Inject(...args: any[]): any
  • A decorator to request from Container that it resolve the annotated property dependency. For example:

    @ AutoWired
    class PersonService {
       constructor (@ Inject creationTime: Date) {
          this.creationTime = creationTime;
       }
       @ Inject
       personDAO: PersonDAO;
    
       creationTime: Date;
    }
    

    When you call:

    let personService: PersonService = Container.get(PersonService);
    // The properties are all defined, retrieved from the IoC Container
    console.log('PersonService.creationTime: ' + personService.creationTime);
    console.log('PersonService.personDAO: ' + personService.personDAO);
    

    Parameters

    • Rest ...args: any[]

    Returns any

InjectParamDecorator

  • InjectParamDecorator(target: Object, propertyKey: string | symbol, parameterIndex: number): void
  • Decorator processor for Inject decorator on constructor parameters

    Parameters

    • target: Object
    • propertyKey: string | symbol
    • parameterIndex: number

    Returns void

InjectPropertyDecorator

  • InjectPropertyDecorator(target: Object, key: string): void
  • Decorator processor for Inject decorator on properties

    Parameters

    • target: Object
    • key: string

    Returns void

Provided

  • Provided(provider: Provider): (Anonymous function)
  • A decorator to tell the container that this class should instantiated by the given Provider. For example:

    @ Provided({get: () => { return new PersonDAO(); }})
    class PersonDAO {
    }
    

    Is the same that use:

    Container.bind(PersonDAO).provider({get: () => { return new PersonDAO(); }});
    

    Parameters

    • provider: Provider

      The provider that will handle instantiations for this class.

    Returns (Anonymous function)

Provides

  • Provides(target: Function): (Anonymous function)
  • A decorator to tell the container that this class should be used as the implementation for a given base class. For example:

    class PersonDAO {
    }
    
    @ Provides(PersonDAO)
    class ProgrammerDAO extends PersonDAO{
    }
    

    Is the same that use:

    Container.bind(PersonDAO).to(ProgrammerDAO);
    

    Parameters

    • target: Function

      The base class that will be replaced by this class.

    Returns (Anonymous function)

Scoped

  • Scoped(scope: Scope): (Anonymous function)
  • A decorator to tell the container that this class should be handled by the provided Scope. For example:

    class MyScope extends Scope {
      resolve(iocProvider:Provider, source:Function) {
        console.log('created by my custom scope.')
        return iocProvider.get();
      }
    }
    @ Scoped(new MyScope())
    class PersonDAO {
    }
    

    Is the same that use:

    Container.bind(PersonDAO).scope(new MyScope());
    

    Parameters

    • scope: Scope

      The scope that will handle instantiations for this class.

    Returns (Anonymous function)

Singleton

  • Singleton(target: Function): void
  • A decorator to tell the container that this class should be handled by the Singleton Scope.

    @ Singleton
    class PersonDAO {
    
    }
    

    Is the same that use:

    Container.bind(PersonDAO).scope(Scope.Singleton)
    

    Parameters

    • target: Function

    Returns void

checkType

  • checkType(source: Object): void
  • Utility function to validate type

    Parameters

    • source: Object

    Returns void

Generated using TypeDoc