You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
In order to avoid declaring an init method inside all services, with often the same things (db, current_user) I use an abstract class that UserService (for example) inherits:
class AbstractService(ABC):
def __init__(self,):
self.config = config
self.session = self.config.get_db()
class UsersService(AbstractService):
def get_users():
**self.session.query....**
But this doesn't work, as the self.session is never set. But if I create a init in UsersService and call the super.init(), then it works.
Hi @djsliders
Thanks for raising this issue. I believe that the problem of this abstraction is due to the implementation of the Injectable decorator. I need to take a second look at this. Maybe you can share the repo you are working on, so i can have a real use case to inspect?
My project is not public sorry. But you can create the default project generated, then add an abstract class on the service, with a init that does self.test = "bla"
Then you will see in your App Service (in debug mode or with a print) that this self.test is never set.
Resolved by the dependency-injection rewrite in #125. @Injectable now preserves the provider class and the container constructs real instances, so a subclass without its own __init__ correctly executes its inherited base-class initializer.
The reported inheritance pattern was reproduced against current main and the inherited state is initialized correctly. Closing as completed.
Activity
ItayTheDar commentedon Oct 10, 2024
Hi @djsliders
Thanks for raising this issue. I believe that the problem of this abstraction is due to the implementation of the Injectable decorator. I need to take a second look at this. Maybe you can share the repo you are working on, so i can have a real use case to inspect?
djsliders commentedon Oct 11, 2024
My project is not public sorry. But you can create the default project generated, then add an abstract class on the service, with a init that does self.test = "bla"
Then you will see in your App Service (in debug mode or with a print) that this self.test is never set.
ItayTheDar commentedon Jul 28, 2026
Resolved by the dependency-injection rewrite in #125.
@Injectablenow preserves the provider class and the container constructs real instances, so a subclass without its own__init__correctly executes its inherited base-class initializer.The reported inheritance pattern was reproduced against current
mainand the inherited state is initialized correctly. Closing as completed.