Pass context to init/destroy listeners if asked. #93

Closed
wants to merge 1 commit into
from

4 participants

@abbot

Sometimes it is required to do something in init/destroy listener depending on servlet context (e.g. load specific configuration bits).

This commit adds an ring option :listeners-with-ctx. If set to true, init and destroy
handlers will be called with a servlet context argument.

@abbot abbot Pass context to init/destroy listeners if asked.
Add an ring option :listeners-with-ctx. If set to true, init and destroy
handlers will be called with a servlet context argument.
4832495
@chptx

that's great, but it should be add to "lein ring server" too.

Agree, but this requires coherent modifications to https://github.com/weavejester/ring-server/blob/master/src/ring/server/standalone.clj, so has do be done gradually.

@MichaelBlume
Collaborator

This looks interesting but is currently unmergeable. I'll look into this in more depth soon -- would you mind resolving the conflicts in the mean time?

@MichaelBlume
Collaborator

Ok, so I'd love to see something like this in lein-ring eventually, this is cool. Here's my thoughts.

a) The ring philosophy seems to be we don't ask webapp authors to deal with hairy java objects with lots of methods they have to read documentation about, we give them, and ask them to return, nice, ednable Clojure literals. Is there a nice way to turn the servlet context into a Clojure literal whose schema we can publish in the docs and so on?

b) I agree with @chptx that this should really be everywhere if it's going to be anywhere. It seems like the best thing is to change ring-server first, with :listeners-with-context as an optional param, and then make the corresponding change herewhen there's a lein-server release that we can upgrade to.

@weavejester
Owner

The problem is how to deal with instances where the :init and :destroy functions are not invoked from a servlet container, and therefore the context is unavailable. Would we just pass a map of options in, and then rely on user code to check if :context was nil or a ServletContext instance?

@MichaelBlume
Collaborator

I'm going to open an issue for this as a future feature and close this pull for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment