On Tue, 2012-01-31 at 15:09 -0800, papagr wrote: > Hello everyone, > > >From the object-oriented point of view, a Pyramid View (instance of a > callable class) depends on the context and the request. Pyramid, > correctly injects those dependencies into the view, during a view's > class instantiation (while processing a Request). > > Assuming that a view depends on other objects to do its job, is there > a preferred or suggested way of injecting other services > (dependencies) in a Pyramid view? By "injecting", I do not mean to use > the Service Locator design pattern, i.e. let the view find its > dependencies using a registry.
If you mean inject stuff into a *view*, you can cause the request to be decorated with arbitrary objects on every request using config.set_request_property (see <http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/api/config.html#pyramid.config.Configurator.set_request_property>). This requires Pyramid 1.3a6+. If you mean inject stuff so that it's present in a template, you can use a BeforeRender event (see <http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/templates.html#using-a-before-render-event-to-expose-an-h-helper-object> ) - C > > For the record, I recently configured and used yaak.inject (http:// > pypi.python.org/pypi/yaak.inject) to a Pyramid project. However, I am > still investigating if there is a better way. > > Cheers, > > Nikolaos Papagrigoriou > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
