I have an AuthModule
in a generalized library which requires interacting with a UserModule
similar to the docs.
What I want to do is define an Interface that the UserService
must adhere to instead of an actual implementation. This will leave the implementation details to the users of the library.
I've tried a few different approaches such as having a string token APP_USER_SERVICE
initially null
then be overridden by the implementor, but this seemed to run into trouble injecting a null
value and not injecting the actual value.
Another approach I tried which I kind of like is doing AuthModule.withUserModule(UserModule)
where AuthModule
imports the dynamic UserModule
and looks for the APP_USER_SERVICE
token defined by the UserModule
implementation. The problem with this approach is it seems to run into circular dependency hell.
I'm new to the NestJS project, so maybe I'm missing something obvious. Any pointers on how to organize this workflow is greatly appreciated, thanks.
In summary this is the structure I am going for:
-> = depends on
LIBRARY:
AuthModule
-> IUserModule
USER:
AuthModule.withUserModule(UserModule)
to fill in the IUserModule
requirement.
UserModule
-> AuthModule
Here is the code (broken atm):
Library
Sample Implementation