Socket
Socket
Sign inDemoInstall

@sport-activities/nuxt-di

Package Overview
Dependencies
0
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @sport-activities/nuxt-di

Dependency Injector


Version published
Maintainers
3
Install size
6.54 kB
Created

Readme

Source

Dependecy Injector

Basic DI that give you access to your services as singletons through this.$services

Installation

npm i -S @nuxt-modules/di  --registry http://nexus3.osiris.withoxylane.com/repository/JSCorp/

Usage

In nuxt.config.js

modules: [
  ...,
  ['@nuxt-modules/di', {
    baseUrl: process.env.BASE_URL
  }],
  ...
]

Nuxt context is automatically injected as first argument of service constructor and you can pass custom data through module options (see example below)

Service classes as to be in a services folder in the project root.

With es6 decorators (experimental)

Adds babel es6 decorator support

npm i -S babel-plugin-transform-decorators-legacy

In nuxt.config.js

build: {
  babel: {
    'plugins': ['transform-decorators-legacy']
  },
  ...
}

Then you have tag your services with the @injectable() decorator.

import injectable from '@nuxt-modules/di/decorators'

@injectable('myUserService')
export default class User {
  constructor ({ app }, { baseUrl }) {
    this.app = app
    this.BASE_URL = baseUrl
  }

  ...
}

For example, this service will be then accessible through this.$services.myUserService

Without es6 decorators

Decorator basically just adds a getInjectableName(void): string method to injected service. So you can avoid decorators usage if you implements the method on your own.

export default class User {
  constructor ({ app }, { baseUrl }) {
    this.app = app
    this.BASE_URL = baseUrl
  }

  getInjectableName() {
    return 'myUserService'
  }
}

FAQs

Last updated on 10 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc