[Grok-dev] Dynamic Adapter Registration

Jeroen Michiel jmichiel at yahoo.com
Fri Feb 6 05:30:06 EST 2009


I'm having a problem dynamically registering adapters.
I'll describe what I want to do, and why (I think) I need this:
I want to be able to have 'configurable' adapters: adapters that all share
the same adapted Interface IA and all provide the same Interface IB, but do
the adaptation in a different, configurable way. To get this working I need
named adapters to distinguish between them. 
Since adapters just have to be callables, what I thought to do was have 1
class that has a __call__ function which accepts 1 parameter of an object
providing IA, then when it is needed, create an object of that class, add it
to the ZODB somechere, and register that object as a named adapter for IA to
IB. These registrations need to be persistent, of course!

But when I try to query for those adapters, the system can't find them! I
tried registering them with zope.component.provideAdapter and
zope.component.registerAdapter, which did not give me errors, but in vain...
I can't use the normal grok.Adapter or grok.adapter way to register them (I
think???), since I'm not using it on a class or function, but on an object,
so I have to be able to do it in 'run-time', but how?

What am I doing wrong here? Or is my concept of using objects as adapters
not such a good idea? If not, how else can I solve this one?
I really need to avoid having to alter code, each time a new adapter needs
to be added.
View this message in context: http://www.nabble.com/Dynamic-Adapter-Registration-tp21869966p21869966.html
Sent from the Grok mailing list archive at Nabble.com.

More information about the Grok-dev mailing list