How to use the @adonisjs/fold.Ioc function in @adonisjs/fold

To help you get started, we’ve selected a few @adonisjs/fold 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 adonisjs / adonis-framework / test / health-check.spec.ts View on Github external
test('define checker as IoC container binding', async (assert) => {
    const ioc = new Ioc()
    const application = new Application(__dirname, ioc, {}, {})
    const healthCheck = new HealthCheck(application)

    class DbChecker {
      public async report () {
        return {
          health: {
            healthy: true,
          },
        }
      }
    }

    ioc.bind('App/Checkers/Db', () => {
      return new DbChecker()
    })
github adonisjs / view / test / view.spec.ts View on Github external
test('register view provider', async (assert) => {
    const ioc = new Ioc()

    ioc.bind('Adonis/Core/Env', () => {
      return {
        get () {},
      }
    })

    ioc.bind('Adonis/Core/Application', () => {
      return {
        viewsPath () {
          return __dirname
        },
      }
    })

    const registrar = new Registrar(ioc)
github adonisjs / ace / test / kernel.spec.ts View on Github external
test('register global boolean flags', async (assert) => {
    assert.plan(2)

    const app = new Application(__dirname, new Ioc(), {}, {})
    const kernel = new Kernel(app)
    kernel.flag('ansi', (ansi, parsed) => {
      assert.equal(ansi, true)
      assert.deepEqual(parsed, { _: [], ansi: true })
    }, {})

    const argv = ['--ansi']
    await kernel.handle(argv)
  })
github adonisjs / assembler / test / make-provider.spec.ts View on Github external
test('make a provider inside the default directory', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({}))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const provider = new MakeProvider(app, new Kernel(app))
    provider.name = 'app'
    await provider.handle()

    const AppProvider = await fs.get('providers/AppProvider.ts')
    const ProviderTemplate = await templates.get('provider.txt')
    assert.deepEqual(
      toNewlineArray(AppProvider),
      toNewlineArray(ProviderTemplate.replace('${filename}', 'AppProvider')),
    )

    const rcContents = await fs.get('.adonisrc.json')
    assert.deepEqual(JSON.parse(rcContents), {
      providers: ['./providers/AppProvider'],
    })
github adonisjs / assembler / test / invoke-command.spec.ts View on Github external
test('execute instructions defined in package.json file', async (assert) => {
    process.env.ADONIS_ACE_CWD = fs.basePath

    await fs.add('node_modules/@adonisjs/sample/package.json', JSON.stringify({
      name: '@adonisjs/sample',
      adonisjs: {
        env: {
          'PORT': '3333',
        },
      },
    }))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const invoke = new Invoke(app, new Kernel(app))
    invoke.name = '@adonisjs/sample'
    await invoke.handle()

    const envFile = await fs.fsExtra.readFile(join(fs.basePath, '.env'), 'utf-8')
    const envExampleFile = await fs.fsExtra.readFile(join(fs.basePath, '.env.example'), 'utf-8')

    assert.equal(envFile.trim(), 'PORT=3333')
    assert.equal(envExampleFile.trim(), 'PORT=')
  })
})
github adonisjs / view / test / view.spec.ts View on Github external
test('share route and signedRoute methods with view', async (assert) => {
    assert.plan(6)
    const ioc = new Ioc()

    ioc.bind('Adonis/Core/Env', () => {
      return {
        get () {},
      }
    })

    ioc.bind('Adonis/Core/Application', () => {
      return {
        viewsPath () {
          return __dirname
        },
      }
    })

    ioc.bind('Adonis/Core/HttpContext', () => {
github adonisjs / assembler / test / make-command.spec.ts View on Github external
test('convert camelcase command path to colon seperated name', async (assert) => {
    await fs.add('.adonisrc.json', JSON.stringify({
      directories: {
        commands: './foo',
      },
    }))

    const app = new Application(fs.basePath, new Ioc(), {}, {})

    const command = new MakeCommand(app, new Kernel(app))
    command.name = 'RunInstructions'
    await command.handle()

    const GreetCommand = await fs.get('foo/RunInstructions.ts')
    const CommandTemplate = await templates.get('command.txt')
    assert.deepEqual(
      toNewlineArray(GreetCommand),
      toNewlineArray(
        CommandTemplate
          .replace('${filename}', 'RunInstructions')
          .replace('${toCommandName(filename)}', 'run:instructions'),
      ),
    )
  })
github adonisjs / adonis-framework / packages / core / src / Ignitor / index.ts View on Github external
private _instantiateIoCContainer () {
    this.ioc = new Ioc(false)

    global['use'] = this.ioc.use.bind(this.ioc)
    global['make'] = this.ioc.make.bind(this.ioc)

    this.ioc.singleton('container', () => this.ioc)
  }
github adonisjs / adonis-framework / src / Ignitor / Bootstrapper / index.ts View on Github external
public setup (): ApplicationContract {
    const ioc = new Ioc()

    /**
     * Adding IoC container resolver methods to the globals.
     */
    global[Symbol.for('ioc.use')] = ioc.use.bind(ioc)
    global[Symbol.for('ioc.make')] = ioc.make.bind(ioc)
    global[Symbol.for('ioc.call')] = ioc.call.bind(ioc)

    const adonisCorePkgFile = findPkg(join(__dirname, '..', '..')).next().value
    const appPkgFile = findPkg(this.appRoot).next().value

    const pkgFile = {
      name: appPkgFile ? appPkgFile.name : 'adonis',
      version: appPkgFile ? appPkgFile.version : '0.0.0',
      adonisVersion: adonisCorePkgFile!.version,
    }
github adonisjs / adonis-framework / src / Ignitor / Ace / CoreCommands.ts View on Github external
private setupApplication () {
    let rcContents = {}

    try {
      rcContents = esmRequire(join(this.appRoot, '.adonisrc.json'))
    } catch (error) {
      if (isMissingModuleError(error)) {
        throw new AceRuntimeException('Make sure the project root has ".adonisrc.json"')
      }
      throw error
    }

    this.application = new Application(this.appRoot, new Ioc(), rcContents, {})
  }