I'm using Pyramid 1.4. I would like to generate some custom Pyramid events from inside my model classes. Events are generated like so:
request.registry.notify(MyCustomEventType("Here it comes"))
As you can see, I need access to the application registry. I'm aware of get_current_registry()
function. But I'm also concerned about this comment from the Pyramid website:
"This function should be used extremely sparingly, usually only in unit testing code"
Questions:
Base
model perhaps?)Rationale:
Basically, I divided my app into features and I try to keep them decoupled. For that, I sometimes need IoC: I was planning on using events as a mean for that. For instance, whenever a user answers a questionare, an event is emitted. Then, such an event can be subscribed to in another parts of the application. I like to keep the application logic in the models and not in the views. Hence, the described issue.
What is the use case for firing the pyramid events from your models? Generally that would be a bad idea.
As for connecting up the app/models. Most of that is done in the initialize call in your main() that passes the settings to the model to give it connection settings and the like. I'd make sure any logic done to tie things together be limited to that single function call on application start up.
In the end though I'd imagine what you want is better done in another way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With