[PEAK] Offering Named Services with configuration keys

Phillip J. Eby pje at telecommunity.com
Wed May 18 20:43:26 EDT 2005

At 12:31 AM 5/19/2005 +0000, Tiago Cogumbreiro wrote:
>Is it possible to offer a [Named Services] as something?
>right now I am obligated to recriate all my components available in
>the service area (created by [Component Factories]) because I can't
>offer a database as a ISQLConnection.
>Example follows:
>[Named Services]
>myapp.db = naming.LinkRef('sqlite:myapp.db')
>[Component Factories]
>myapp.model.SomeDM = "myapp.storage.SomeDM"
># Problem:
># I need to offer to my DM's a ISQLConnection
># The PropertyName("myapp.db") should be offered as an storage.ISQLConnection
># Because I can't I have to recriate all the components and offer them again:
>MyBaseComponet (binding.Component):
>     # Override the DM so that further calls get this component instead
>     SomeDM = binding.Make (myapp.model.SomeDM, offerAs=[myapp.model.SomeDM]
>     # Override the DB property so that it offers a ISQLConnection:
>     db = binding.Obtain (PropertyName("myapp.db"),

I don't understand.  Are you saying that SomeDM relies on a generic 
ISQLConnection?  That sounds wrong to me.  Surely it requires something 
more specific than just any old database connection?

>What am I doing wrong? Is it possible to workaround this problem? I
>guess the main question is: is it possible to fiddle with the objects
>in the service area, such as changing what they offer? And can this
>all be made in the configuration level? I would really like my
>component to be something like:
>MyBaseComponet (binding.Component):
>     # I'm just going to need my DM, he needs a ISQLConnection but
>     # my named service myapp.db is already offered as such.
>     SomeDM = binding.Obtain (myapp.model.SomeDM)

The correct way to do this, if I understand your use case correctly, is to 
make the DM's depend on a *specific* interface that describes what they 
actually require.  Then, set up a [Component Factories] entry that maps 
that specific interface over to myapp.db.

More information about the PEAK mailing list