UNPKG

@vert/core

Version:

Library to build OOP applications which are based on Vue.

80 lines (63 loc) 1.64 kB
# Register service Before injecting a service into vue component, you should register it into your app. ```typescript // Your services. import { Injectable } from '@vert/core' @Injectable() class HttpService { } @Injectable() class BookshelfService { constructor ( private httpSrv: HttpService ) {} } @Injectable() class UserService { constructor ( private httpSrv: HttpService ) {} } export { BookshelfService, UserService } ``` Registration: ```typescript import { App } from '@vert/core' // You have these two services and you should register theme for your app. import { BookshelfService, HttpService, UserService } from './services' // Registration. // You will get different instances of these services in every single initialization. App.addTransient(BookshelfService, HttpService, UserService) // You will get the same instance of these every single service. App.addSingleton(BookshelfService, HttpService, UserService) // For more detail about this behavior, please check "05.use-injector.md". ``` ## API ```typescript /** * App is the basic unit for a project. * * @class App */ class App { /** * Register target as a singleton provider in global. * * @static * @template T * @param {TConstructor[]} Providers */ static addSingleton (...Providers: TConstructor[]): typeof App /** * Register target as a transient provider in global. * * @static * @template T * @param {TConstructor[]} Providers */ static addTransient (...Providers: TConstructor[]): typeof App } ```