Socket
Socket
Sign inDemoInstall

awilix

Package Overview
Dependencies
23
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install
Previous1245
9Next

4.2.6

Diff

Changelog

Source

v4.2.6

  • Fix return type for createScope when using a cradle typing. (#182, moltar)
  • Remove yarn.lock, contributing docs now recommend npm.
  • Update packages, upgrade to Prettier 2.0
jeffijoe
published 4.2.5 •

Changelog

Source

v4.2.5

  • Add optional generic parameter to container typing. Allows for a typed ICradle. (#169, roikoren755)
jeffijoe
published 4.2.4 •

Changelog

Source

v4.2.4

jeffijoe
published 4.2.3 •

Changelog

Source

v4.2.3

  • Fix issue where calling JSON.stringify on the cradle would result in memory leak (#153, berndartmueller)
  • Update packages
jeffijoe
published 4.2.2 •

Changelog

Source

v4.2.2

  • Fix issue where the tokenizer was being too eager. (#30)
  • Make tests pass on Node v12
  • Update packages
jeffijoe
published 4.2.1 •

Changelog

Source

v4.2.1

  • Fix register option in loadModules (#124)
  • Update packages
jeffijoe
published 4.2.0 •

Changelog

Source

v4.2.0

  • Add has method to container to check for an existing registration (#119, faustbrian)
jeffijoe
published 4.1.0 •

Changelog

Source

v4.1.0

  • Extract dependencies from base class when no parameters were extracted. This works for ES6 classes as well as the old-school prototype approach to inheritance. Uses Object.getPrototypeOf. (#107)
  • Allow auto-loading of named exports that expose a RESOLVER symbol prop. (#115)
jeffijoe
published 4.0.1 •

Changelog

Source

v4.0.1

  • Support returning the cradle in async functions (#109, andyfleming))
  • Update packages
jeffijoe
published 4.0.0 •

Changelog

Source

v4.0.0

  • [BREAKING CHANGE]: Scoped containers no longer use the parent's cache for Lifetime.SCOPED registrations (#92)
  • Change the "react-native" module path to use awilix.browser.js (#104)
  • Update packages

Awilix v4 corrects a misunderstanding in how the scoped caching should work. For full context, please see issue #92, but the TL:DR version is that prior v4, scoped registrations (Lifetime.SCOPED / .scoped()) would travel up the family tree and use a parent's cached resolution if there is any. If there is not, the resolving scope would cache it locally.

While this was by design, it was not very useful, and it was designed based on a misunderstanding of how Unity's HierarchicalLifetimeManager works. In v4, Lifetime.SCOPED now works the same way: the container performing the resolution also caches it, not looking outside itself for cached resolutions of Lifetime.SCOPED registrations.

A prime use case for this is having a scoped logger, as well as a root logger. This is actually what prompted this change.

// logger.js
export class Logger {
  constructor(loggerPrefix = 'root') {
    this.prefix = loggerPrefix
  }

  log(message) {
    console.log(`[${this.prefix}]: ${message}`)
  }
}
// app.js
import { Logger } from './logger'
import { createContainer, asClass, InjectionMode } from 'awilix'

const container = createContainer({
  injectionMode: InjectionMode.CLASSIC,
}).register({
  logger: asClass(Logger).scoped(),
})

const scope = container.createScope()
scope.register({
  loggerPrefix: asValue('dope scope'),
})

const rootLogger = container.resolve('logger')
const scopeLogger = scope.resolve('logger')

rootLogger.log('yo!') // [root]: yo!
scopeLogger.log('wassup!') // [dope scope]: wassup!

Prior to v4, the scopeLogger would have resolved to the same as rootLogger because it would ask it's ancestors if they had a logger cached. Now it works as you would probably expect it to: it keeps it's own cache.

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