diff --git a/package.json b/package.json index 1d27e02..dac12c7 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "author": "Talysson ", "license": "MIT", "dependencies": { - "awilix": "^2.2.3", + "awilix": "^3.0.9", "awilix-express": "^0.11.0", "body-parser": "^1.17.1", "compression": "^1.6.2", diff --git a/src/container.js b/src/container.js index 8621601..e3b8e84 100644 --- a/src/container.js +++ b/src/container.js @@ -1,4 +1,4 @@ -const { createContainer, Lifetime } = require('awilix'); +const { createContainer, asClass, asFunction, asValue } = require('awilix'); const { scopePerRequest } = require('awilix-express'); const config = require('../config'); @@ -28,50 +28,52 @@ const container = createContainer(); // System container - .registerClass({ - app: [Application, { lifetime: Lifetime.SINGLETON }], - server: [Server, { lifetime: Lifetime.SINGLETON }] + .register({ + app: asClass(Application).singleton(), + server: asClass(Server).singleton() }) - .registerFunction({ - router: [router, { lifetime: Lifetime.SINGLETON }], - logger: [logger, { lifetime: Lifetime.SINGLETON }] + .register({ + router: asFunction(router).singleton(), + logger: asFunction(logger).singleton() }) - .registerValue({ config }); + .register({ + config: asValue(config) + }); // Middlewares container - .registerFunction({ - loggerMiddleware: [loggerMiddleware, { lifetime: Lifetime.SINGLETON }] + .register({ + loggerMiddleware: asFunction(loggerMiddleware).singleton() }) - .registerValue({ - containerMiddleware: scopePerRequest(container), - errorHandler: config.production ? errorHandler : devErrorHandler, - swaggerMiddleware: [swaggerMiddleware] + .register({ + containerMiddleware: asValue(scopePerRequest(container)), + errorHandler: asValue(config.production ? errorHandler : devErrorHandler), + swaggerMiddleware: asValue([swaggerMiddleware]) }); // Repositories -container.registerClass({ - usersRepository: [SequelizeUsersRepository, { lifetime: Lifetime.SINGLETON }] +container.register({ + usersRepository: asClass(SequelizeUsersRepository).singleton() }); // Database -container.registerValue({ - database, - UserModel +container.register({ + database: asValue(database), + UserModel: asValue(UserModel) }); // Operations -container.registerClass({ - createUser: CreateUser, - getAllUsers: GetAllUsers, - getUser: GetUser, - updateUser: UpdateUser, - deleteUser: DeleteUser +container.register({ + createUser: asClass(CreateUser), + getAllUsers: asClass(GetAllUsers), + getUser: asClass(GetUser), + updateUser: asClass(UpdateUser), + deleteUser: asClass(DeleteUser) }); // Serializers -container.registerValue({ - userSerializer: UserSerializer +container.register({ + userSerializer: asValue(UserSerializer) }); module.exports = container; diff --git a/yarn.lock b/yarn.lock index 6efc452..8631ec8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -212,15 +212,12 @@ awilix-express@^0.11.0: version "0.11.0" resolved "https://registry.yarnpkg.com/awilix-express/-/awilix-express-0.11.0.tgz#6c41d30219dea53b83982045c5235b4804791425" -awilix@^2.2.3: - version "2.2.3" - resolved "https://registry.yarnpkg.com/awilix/-/awilix-2.2.3.tgz#a6e10a37a4eec59056bf1bd1bfe386475e7688f5" +awilix@^3.0.9: + version "3.0.9" + resolved "https://registry.yarnpkg.com/awilix/-/awilix-3.0.9.tgz#3bd5cdf1d95b02888a8dc937fdb4d31e790b6380" dependencies: camel-case "^3.0.0" - glob "^7.1.1" - is-class "0.0.4" - is-plain-object "^2.0.1" - is-string "^1.0.4" + glob "^7.1.2" aws-sign2@~0.6.0: version "0.6.0" @@ -1825,10 +1822,6 @@ is-builtin-module@^1.0.0: dependencies: builtin-modules "^1.0.0" -is-class@0.0.4: - version "0.0.4" - resolved "https://registry.yarnpkg.com/is-class/-/is-class-0.0.4.tgz#e057451705bb34e39e3e33598c93a9837296b736" - is-dotfile@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.2.tgz#2c132383f39199f8edc268ca01b9b007d205cc4d" @@ -1895,12 +1888,6 @@ is-path-inside@^1.0.0: dependencies: path-is-inside "^1.0.1" -is-plain-object@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.1.tgz#4d7ca539bc9db9b737b8acb612f2318ef92f294f" - dependencies: - isobject "^1.0.0" - is-posix-bracket@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" @@ -1927,10 +1914,6 @@ is-stream@^1.0.0, is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" -is-string@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.4.tgz#cc3a9b69857d621e963725a24caeec873b826e64" - is-typedarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" @@ -1959,10 +1942,6 @@ isexe@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/isexe/-/isexe-1.1.2.tgz#36f3e22e60750920f5e7241a476a8c6a42275ad0" -isobject@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/isobject/-/isobject-1.0.2.tgz#f0f9b8ce92dd540fa0740882e3835a2e022ec78a" - isobject@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89"