How to use the midway.scope function in midway

To help you get started, we’ve selected a few midway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midwayjs / midway-examples / demo-plugin-egg-acm / src / lib / acm_sercice.ts View on Github external
import { scope, ScopeEnum, provide, init, plugin } from 'midway';

const dataId = 'acm.test.1';
const group = 'DEFAULT_GROUP';

@provide()
@scope(ScopeEnum.Singleton)
export class ACMService {

  acmText;

  @plugin()
  acm;

  @init()
  async init() {
    // 放在这里是因为设置成了单例,全局只会有一份实例
    const str = `example_test_${Math.random()}_${Date.now()}`;
    await this.acm.publishSingle(dataId, group, str);

    this.acm.subscribe({
      dataId,
      group
github midwayjs / midway-examples / demo-sequelize-typescript / src / lib / model / db.ts View on Github external
import { Sequelize } from 'sequelize-typescript';
import { provide, scope, ScopeEnum } from 'midway';
import { PostModel } from './post';

interface ISequelizeConfig {
  host: string;
  port: number;
  user: string;
  password: string;
  database: string;
  dialect: string;
}

// providing DB.sequelize in case of hyper features
// of sequelize like "sequelize.transaction"
@scope(ScopeEnum.Singleton)
@provide('DB')
export class DB {
  public static sequelize: Sequelize;

  public static async initDB(config: ISequelizeConfig) {
    DB.sequelize = new Sequelize(
      {
        database: config.database,
        username: config.user,
        password: config.password,
        dialect: config.dialect,
        host: config.host,
        port: config.port,
        timezone: '+08:00',
        logging: false,
        operatorsAliases: false,
github midwayjs / midway-examples / demo-sequelize / src / lib / model / db.ts View on Github external
import { async, config, init, provide, scope, ScopeEnum } from 'midway';
import { Options, Sequelize } from 'sequelize';

export interface IDBOptions extends Options {
  database: string;
  username: string;
  password: string;
}

export interface IDB {
  sequelize: Sequelize;
  options: IDBOptions;
}
@scope(ScopeEnum.Singleton)
@async()
@provide('DB')
export default class DB implements IDB {
  public sequelize: Sequelize;

  @config('sequelize')
  public options: IDBOptions;

  @init()
  public connect() {
    this.sequelize = new Sequelize(
      this.options.database,
      this.options.username,
      this.options.password,
      {
        dialect: this.options.dialect,
github midwayjs / midway-examples / demo-nacos / src / service / namingService.ts View on Github external
import { provide, init, config, scope, ScopeEnum, logger } from 'midway';

const NacosNamingClient = require('nacos').NacosNamingClient;

@provide()
@scope(ScopeEnum.Singleton)
export class NamingService {

  nacosClient;

  @config('nacosNaming')
  nacosConfig;

  @logger()
  logger;

  @init()
  async init() {
    this.nacosClient = new NacosNamingClient({
      ...this.nacosConfig,
      logger: this.logger,
      namespace: 'public',

midway

A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade.

MIT
Latest version published 3 years ago

Package Health Score

60 / 100
Full package analysis