Hi All,

Firsly, a few comments on the book chapter relating to this:

- The example on page 233 and the first one on page 234 both import 
getGlobalSiteManager even though it's not used in the example.

- The example on page 235 calls hook_zca() even though I believe this 
has the opposite effect to the documented one.

So, the problem I have is that I have a couple of packages that register 
utilities with the ZCA. Those utilities are then looked up in 
application code.

The registrations are all ensured to take place after config.begin() and 
before config.end().

However, the application code is not always inside the handling of a BFG 
request. Some code also runs when the application recieves incoming 
stomp messages. I originally had this code create a fake http request 
and fire that at Twisted's WSGI server. However, that sucked in some 
fairly fundamental ways. So, that code no longer runs inside a "bfg 

I originally followed ChrisM's IRCadvice on this; just used the registry 
attached to the config or the request. But, that made my packages 
dependent on repoze.bfg, when they had no other need to be.

So, I dropped back to using getSiteManager().registerUtility and 
getSiteManager().getUtility and used hook_zca as recommended in the docs.

The problem here was that while the registrations were done in the 
app-specific registry, this registry had been popped off the threadlocal 
stack by the time my stomp message code was called.

So, I either had to teach the stomp message code about the BFG registry 
stack, and then mimic the BFG code that pushes the config's registry 
onto the stack for the duration of the handling of the message. That 
would once again make my packages dependent on repoze.bfg for artificial 
reasons, even more so this time!

So, I went for the recipe in 26.1.3 in the book. However, this still has 
the same problem because of the hook_zca call; during configuration, the 
ZCA global registry is used, but without the aforementioned teaching and 
mimicking, I now have the *repoze.bfg.registry* global registry on the 
stack (which still doesn't have my registrations) when my stomp handling 
application code is called.

So, I currently do this during app setup:

def app(global_config, **settings):
     registry = getGlobalSiteManager()
     config = Configurator(registry=registry)

     ... do registrations...

     return config.make_wsgi_app()

(note the absence of hook_zca)

This appears to work, but is it "right"? Am I going to get bitten by 
"something weird" later down the line?



Repoze-dev mailing list

Reply via email to