Comments (17)
It looks like you are mixing injection modes, but its hard to tell without your container configuration
from awilix.
thanks for your reply
here are my container configuration
const container = awilix.createContainer();
class Container {
constructor(keys) {
container.register({
config: `awilix.asClass(config).setInjectionMode(awilix.InjectionMode.CLASSIC).singleton(),`
authenticationService : awilix.asClass(AuthenticationService),
authenticationController : awilix.asClass(AuthenticationController),
DateUtil : awilix.asValue(DateUtil),
RestUtil : awilix.asClass(RestUtil),
CommonUtil : awilix.asValue(CommonUtil),
MailUtil : awilix.asValue(MailUtil),
MessageUtil : awilix.asValue(MessageUtil),
OauthUtil : awilix.asClass(OauthUtil),
}),
this.resolve = this.resolve.bind(this);
}
resolve(key) {
return container.resolve(key);
}
}
module.exports = Container;
from awilix.
Yes, as I suspected, you are mixing injection modes which I don’t recommend. One of your modules are likely treating a parameter as some other module but in reality its the container cradle (proxy).
from awilix.
so now did some changes in code
const container = awilix.createContainer();
class Container {
constructor(keys) {
container.register({
config: awilix.asClass(config).singleton(),
authenticationService: awilix.asClass(AuthenticationService),
authenticationController: awilix.asClass(AuthenticationController),
RestUtil: awilix.asClass(RestUtil),
OauthUtil: awilix.asClass(OauthUtil),
DateUtil: awilix.asValue(DateUtil),
CommonUtil: awilix.asValue(CommonUtil),
MailUtil: awilix.asValue(MailUtil),
MessageUtil: awilix.asValue(MessageUtil),
}),
this.resolve = this.resolve.bind(this);
}
resolve(key) {
return container.resolve(key);
``
from awilix.
Either avoid mixing injection modes or find the module that is assuming CLASSIC
but is actually using PROXY
(default).
from awilix.
so now i am only using proxy as an injection mode but it is giving me the same error
AwilixResolutionError: Could not resolve 'Symbol(Symbol.toPrimitive)'.
Resolution path: Symbol(Symbol.toPrimitive)
``
from awilix.
What are you resolving first?
from awilix.
i am resoling authenticationController in my authenticationRouter module
const Container = require("../container") ;
const ContainerINST = new Container() ;
const AUTHENTICATIONCONTROLLERINST = ContainerINST.resolve("authenticationController") ;``
from awilix.
Then look at the constructor of AuthenticationController
, you are likely treating it as CLASSIC
even though it's registered as PROXY
.
from awilix.
here is the constructor of authentication controller
class AuthenticationController {
constructor({authenticationService, config, DateUtil,RestUtil, CommonUtil, MessageUtil, OauthUtil}) {
this.DateUtil = DateUtil ;
this.config = config ;
// console.log("config here:::::::::::", this.config)
this.authService = authenticationService;
// this.authService = new AUTHENTICATIONSERVICE(config);
this.rbacController = new RBACCONTROLLER(this.config);
this.restUtil = RestUtil;
this.OauthUtil = OauthUtil;
this.CommonUtil = CommonUtil;
this.MessageUtil = MessageUtil ;
from awilix.
What is the full stack trace of the error?
from awilix.
so what im doing is im resolving the AuthentiationController
from theAuthenticationRoute
const Container = require("../container") ;
const ContainerINST = new Container() ;
const AUTHENTICATIONCONTROLLERINST = ContainerINST.resolve("authenticationController") ;
then im calling FindUserByEmailForLogin
function from the AuthentiationController
router.get("/login/:email",checkJwt, AUTHENTICATIONVALIDATIONINST.findUserByEmailForLogin(), result_validator, AUTHENTICATIONCONTROLLERINST.findUserByEmailForLogin);
and then in AuthentiationController
constructor im destructing the dependcies
class AuthenticationController {
constructor({authenticationService, config, DateUtil,RestUtil, CommonUtil, MessageUtil, OauthUtil}) {
this.DateUtil = DateUtil ;
this.config = config ;
// console.log("config here:::::::::::", this.config)
this.authService = authenticationService;
// this.authService = new AUTHENTICATIONSERVICE(config);
this.rbacController = new RBACCONTROLLER(this.config);
this.restUtil = RestUtil;
this.OauthUtil = OauthUtil;
this.CommonUtil = CommonUtil;
this.MessageUtil = MessageUtil ;
and In FindUserByEmailForLogin
im calling a function from OauthUtil
(i pass OauthUtil
as dependency in AuthentiationController
)
class OauthUtil {
constructor({config, RestUtil, CommonUtil, MessageUtil}) {
console.log("here in the oath Util")
this.config = config;
this.CommonUtil = CommonUtil;
this.restUtil = RestUtil;
this.MessageUtil = MessageUtil;
this.mongoose = new MONGOOSEDB();
and then In OauthUtil
's Function CreateAccessToken
I am using RestUtil
which i pass as an dependency in OauthUtil
's constructor
async createAccessToken(type, update_time) {
try {
let data = {
"client_id": this.config.get('client_id'),
"client_secret": this.config.get('client_secret'),
"audience": `${this.config.get('audience_management_api')}`,
"grant_type": "client_credentials"
};
let options = {
headers: { 'content-type': 'application/json' },
}
let url = this.config.get('oauth:token_url');
let response = await this.restUtil.postRequest(url, data, options);
this.storeAccessToken(type, response.data, update_time, this.MessageUtil.info().oauth_token.management)
return response.data;
} catch (err) {
console.log("err createAcceessToken:::", err)
throw new Error(err);
}
}
when i restUtil
Try to call its function PostRequest
its is giving me an error
from awilix.
createAcceessToken::: AwilixResolutionError: Could not resolve 'Symbol(Symbol.toPrimitive)'.
Resolution path: Symbol(Symbol.toPrimitive)
at resolve (/home/kirat/microservices/authentication_managing_microservice/backend/microservice/authentication/node_modules/awilix/lib/container.js:252:23)
at Object.get (/home/kirat/microservices/authentication_managing_microservice/backend/microservice/authentication/node_modules/awilix/lib/container.js:66:33)
at parseInt (<anonymous>)
at dispatchHttpRequest (/home/kirat/microservices/authentication_managing_microservice/backend/node_modules/axios/lib/adapters/http.js:342:21)
at new Promise (<anonymous>)
at httpAdapter (/home/kirat/microservices/authentication_managing_microservice/backend/node_modules/axios/lib/adapters/http.js:48:10)
at dispatchRequest (/home/kirat/microservices/authentication_managing_microservice/backend/node_modules/axios/lib/core/dispatchRequest.js:58:10)
at Axios.request (/home/kirat/microservices/authentication_managing_microservice/backend/node_modules/axios/lib/core/Axios.js:108:15)
at Axios.<computed> [as post] (/home/kirat/microservices/authentication_managing_microservice/backend/node_modules/axios/lib/core/Axios.js:140:17)
at Function.wrap [as post] (/home/kirat/microservices/authentication_managing_microservice/backend/node_modules/axios/lib/helpers/bind.js:9:15)
errr::::::::: Error: AwilixResolutionError: Could not resolve 'Symbol(Symbol.toPrimitive)'.
Resolution path: Symbol(Symbol.toPrimitive)
at OauthUtil.createAccessToken (/home/kirat/microservices/authentication_managing_microservice/backend/common/utils/Oauth-util.js:61:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async OauthUtil.getAccessToken (/home/kirat/microservices/authentication_managing_microservice/backend/common/utils/Oauth-util.js:31:29)
at async AuthenticationController.findUserByEmailForLogin (/home/kirat/microservices/authentication_managing_microservice/backend/microservice/authentication/controller/authentication-controller.js:692:19)
undefined Error: Error: AwilixResolutionError: Could not resolve 'Symbol(Symbol.toPrimitive)'.
Resolution path: Symbol(Symbol.toPrimitive)
at OauthUtil.getAccessToken (/home/kirat/microservices/authentication_managing_microservice/backend/common/utils/Oauth-util.js:40:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async AuthenticationController.findUserByEmailForLogin (/home/kirat/microservices/authentication_managing_microservice/backend/microservice/authentication/controller/authentication-controller.js:692:19)
from awilix.
If you look at the stack trace, it'll give you some hints. For example, Axios' dispatchHttpRequest
is somehow triggering resolve
in Awilix. This likely means you passed in the cradle
somewhere to Axios, likely in your restUtil
.
Looking at Axios's source code, there is exactly one parseInt
in dispatchHttpRequest
, which is parsing a timeout
config. So my guess is your restUtil
is passing in the cradle, which in turn makes parseInt
attempt to convert the value to a primitive by x[Symbol.toPrimitive]
, which then triggers the resolve
.
from awilix.
hi jeff thanks for your help my pervious error got resolved..
now what i m trying to do is register dependencies using loadModules
but loadModules
is not working as it is not registering any dependencies
my code :
` .loadModules([
"service/**/*",
"controller/**/*",
"routes/**/*",
],
{
resolverOptions: {
lifetime: awilix.Lifetime.SCOPED,
register: awilix.asClass,
},
formatName: 'camelCase'
}
)
this.resolve = this.resolve.bind(this);
console.log("In the container.js",container.registrations )
}`
app structure::
-->app
-->service
->userService
->anyotherservice
-->controller
->userController
->anyotherController
-->routes
->userRoutes
->anyotherRoutes
-->Contanier.js
ERROR : AwilixResolutionError: Could not resolve 'authenticationRoute'.
any Suggestions or advice :)
from awilix.
Have you followed the documentation for how to set up your modules for auto-loading?
from awilix.
Closing this since it's not an issue.
from awilix.
Related Issues (20)
- [Question] Support for assisted inject HOT 2
- awilix object is undefined when using default import, but named import of functions work HOT 1
- Support for ESM modules HOT 3
- Is it possible to reinforce constructor param name/types? HOT 1
- Can't resolve HOT 4
- How to unregister a dependency from the container? HOT 6
- Default value not working in class constructor in Proxy mode HOT 2
- asFunction -> asClass Cyclic dependency HOT 2
- Awilix TypeError: Cannot read properties of undefined (reading 'cache') HOT 2
- Calling `loadModules` does not register all the file paths HOT 2
- Is it possible to detect / error on singletons dependent on transient or scoped registrations? HOT 1
- Awilix 10 type exposure HOT 1
- [QUESTION] Userland async initializers HOT 7
- replace camel-case dependency HOT 3
- Possible valid use-case for disabling strict mode for specific resolver HOT 2
- Critical dependency: the request of a dependency is an expression HOT 3
- Add TypeScript support HOT 1
- [QUESTION] - Awilix Fails to Autoload Modules in Vitest Tests with TypeScript Setup HOT 1
- How can I get scope inside instance? HOT 14
- [QUESTION] - How to find registered but not used containers? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awilix.