fukamachi / ningle

Super micro framework for Common Lisp
http://8arrow.org/ningle/
273 stars 25 forks source link

Context not accessible #6

Open otwieracz opened 9 years ago

otwieracz commented 9 years ago

Hello,

context seems not working in ningle:

CL-USER> (ql:quickload :ningle)
To load "ningle":
  Load 1 ASDF system:
    ningle
; Loading "ningle"
.........................
(:NINGLE)
CL-USER> (defvar *app* (make-instance 'ningle:<app>))
*APP*
CL-USER> 
(setf (ningle:route *app* "/")
      "Welcome to ningle!")
"Welcome to ningle!"
CL-USER> (clack:clackup (lack:builder *app*))
To load "lack-middleware-backtrace":
  Load 1 ASDF system:
    lack-middleware-backtrace
; Loading "lack-middleware-backtrace"

To load "clack-handler-hunchentoot":
  Load 1 ASDF system:
    clack-handler-hunchentoot
; Loading "clack-handler-hunchentoot"

Hunchentoot server is started.
Listening on localhost:5000.
#S(CLACK.HANDLER::HANDLER
   :SERVER :HUNCHENTOOT
   :ACCEPTOR #<SB-THREAD:THREAD "clack-handler-hunchentoot" RUNNING
                {10048B4133}>)
CL-USER> (setf (ningle:context :foo) 'bar)

The value NIL is not of type HASH-TABLE.
   [Condition of type TYPE-ERROR]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] abort thread (#<THREAD "new-repl-thread" RUNNING {100521F363}>)

Backtrace:
  0: (SB-KERNEL:%PUTHASH :FOO NIL BAR) [tl,external]
  1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SETF (NINGLE.CONTEXT:CONTEXT :FOO) (QUOTE BAR)) #<NULL-LEXENV>)
  2: (EVAL (SETF (NINGLE.CONTEXT:CONTEXT :FOO) (QUOTE BAR)))

Am I doing something wrong or there is some problem with Ningle/Clack?

fukamachi commented 9 years ago

Context is intended to be for each request, so use it in controllers.

a13x commented 7 years ago

bumping this thread as I encountered a similar situation: if context is intended to be used in controllers, how can we set it up so it's available for the whole app (like db connections, etc). Is there a way to do it on app setup or..?

fukamachi commented 7 years ago

Global context is not actually "context". Use a special variable instead. See also Envy, a configuration switcher.

a13x commented 7 years ago

Then you should consider changing the "context" session in the README as it is misleading. For example, clarifying what the context is actually useful for and an example usage.

dnaeon commented 1 year ago

@a13x , @otwieracz , joining a bit late, but I had a similar use case, which I've fixed using the following approach. Hope it helps.

https://gist.github.com/dnaeon/3a3f86dea1096db5a9231d1f56a565e2