Question: passing attributes from service to dependencies

I have a service that has a session as an attribute, i want to be able to
pass that into a dependency. only problem is i can't see any way to get
data from the service class in the dependency provider.

Any help please?

In the DependencyProvider get_dependency method i've tried using
`worker_ctx.service.db`, but that just passes the instance of the
DependencyProvider, not what get_dependency is suppose to return.

Using the injected dependency from one DependencyProvider inside another
one isn't recommended. The 'db' attribute on your service instance will be
the dependency provider instance before injection happens, and the injected
session afterwards. Injection happens here:
https://github.com/nameko/nameko/blob/fd8ffdd210249f752215a58ec8545c105ca18d41/nameko/containers.py#L412-L415\.

I guess you're trying to share a database session between dependency
providers? Is there a reason the DPs can't have their own sessions? More
detail on your use-case would be helpful.

···

On Monday, November 20, 2017 at 4:45:11 AM UTC, kirkdouglasj...@gmail.com wrote:

I have a service that has a session as an attribute, i want to be able to
pass that into a dependency. only problem is i can't see any way to get
data from the service class in the dependency provider.

Any help please?

In the DependencyProvider get_dependency method i've tried using
`worker_ctx.service.db`, but that just passes the instance of the
DependencyProvider, not what get_dependency is suppose to return.

No reason, i later read that it will be better not to use an injected
dependency into another, will make testing hard.

My issue was just passing passing the same session every repeatedly...

but, now that you mention it, each dependency having their own session
sounds, actually way way, better.

Thank you, don't know why i never thought about that myself lol.

···

On Monday, November 20, 2017 at 4:48:01 AM UTC-5, Matt Yule-Bennett wrote:

On Monday, November 20, 2017 at 4:45:11 AM UTC, kirkdouglasj...@gmail.com > wrote:

I have a service that has a session as an attribute, i want to be able to
pass that into a dependency. only problem is i can't see any way to get
data from the service class in the dependency provider.

Any help please?

In the DependencyProvider get_dependency method i've tried using
`worker_ctx.service.db`, but that just passes the instance of the
DependencyProvider, not what get_dependency is suppose to return.

Using the injected dependency from one DependencyProvider inside another
one isn't recommended. The 'db' attribute on your service instance will
be the dependency provider instance before injection happens, and the
injected session afterwards. Injection happens here:
https://github.com/nameko/nameko/blob/fd8ffdd210249f752215a58ec8545c105ca18d41/nameko/containers.py#L412-L415
.

I guess you're trying to share a database session between dependency
providers? Is there a reason the DPs can't have their own sessions? More
detail on your use-case would be helpful.