How to use import instead of ioc.use when use Env library?


#1

I want to use es6 import when using adonis libraries.

// this
const Route = use('Route')
// can be subsituted with
import Route from '@adonisjs/framework/src/Route/Manager'

// but this
const Env = use('Env')
// can not be subsituted with
import Env from '@adonisjs/framework/src/Env'

What did I do wrong?


#2

You cannot !

Please, read :


#3

In short

The use method resolves the dependency from IoC container

The import keyword and require resolves it from file system.

Though the dependency inside IoC Container will be file-system, but the IoC container, but they both are not same.

Understanding IoC container will take some of your time, so If interested, please read the docs http://dev.adonisjs.com/docs/4.0/ioc-container