Anyone here implement Context objects as ZCA adapters?

40 views
Skip to first unread message

Iain Duncan

unread,
Dec 6, 2017, 12:09:07 PM12/6/17
to object-composition
Just curious if there are any other python ZCA users on here, and if anyone uses ZCA adapters as a way to find and instantiate Context objects. It seems to me a natural fit, but I am probably missing a lot here. I like the idea of being able to give one Controller the ability to seamlessly instantiate different kinds of Context objects passed on interface decoration or class of the participants (and perhaps the current web request, as Pyramid does for View lookup).

thanks
Iain

Andreas Söderlund

unread,
Dec 12, 2017, 7:19:11 AM12/12/17
to object-co...@googlegroups.com
Hello Iain, I have a quick reflection about your question: Dependency Injection is about decoupling and reusability, technical aspects not related to DCI, perhaps even frowned upon when the user-friendly DCI gets mixed up with these kind of engineering artefacts. It's similar to if the plumbing and electric wires of a house would decide the architecture.

With DI the system will select what objects to inject (mostly services?) based on configuration, which I think is a mismatch against the dynamic nature of Contexts. The bank transfer for example, as well as most Contexts I've written, gathers the objects based on some identifier. Several bank transfers can happen at the same time in a system, with credentials inputted by the user. I don't think any DI configuration could support such a scenario.

I hope that gives you an idea of the differences?

/Andreas

--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to object-composit...@googlegroups.com.
To post to this group, send email to object-co...@googlegroups.com.
Visit this group at https://groups.google.com/group/object-composition.
For more options, visit https://groups.google.com/d/optout.

James O Coplien

unread,
Dec 12, 2017, 7:49:00 AM12/12/17
to object-co...@googlegroups.com


Den 12. dec. 2017 kl. 13.18 skrev Andreas Söderlund <cisc...@gmail.com>:

Several bank transfers can happen at the same time in a system, with credentials inputted by the user. I don't think any DI configuration could support such a scenario.

I was with you up until this point. I don’t see why it wouldn’t also work with DI.

Do you have the Elephant article? I spent a bit of time on DI therein.

Andreas Söderlund

unread,
Dec 14, 2017, 3:45:13 AM12/14/17
to object-co...@googlegroups.com
Yes, I've read the old version of the article (love the constrictor part), and I guess you're right, configuring the DI library to handle user credentials would be possible, but is it feasible separating the whole construction part of the system like that? In the bank transfer example, wouldn't that mean putting the whole authentication process into the configuration?

--

James O Coplien

unread,
Dec 14, 2017, 7:13:34 AM12/14/17
to object-co...@googlegroups.com
I think the best way to answer this question is to try.

Matthew Browne

unread,
Dec 14, 2017, 9:04:36 AM12/14/17
to object-co...@googlegroups.com
It's not all or nothing of course...for example, I would probably use dependency injection for services like ORM or logging libraries, but not for instantiating data objects.
--
Sent from my Android device with K-9 Mail.

Iain Duncan

unread,
Dec 22, 2017, 10:04:13 AM12/22/17
to object-composition
Thanks everyone. The thing I like about the ZCA's DI system it has the notion of lookup by adapter, wherein the interface hierarchy of the thing you're adapting can determine what you get out of the DI system. IE: get me the Foobar service that is appropirate for working with the type of thing I already have. This seems to me a good fit for some DCI concepts, so I was curious if others were doing that and what they had found, as I'm new to DCI. 

I will indeed give it a good try and find out!

thanks
Iain
Reply all
Reply to author
Forward
0 new messages