Hi, I am pleased to announce a new dependency injection container - 
dar/container <https://github.com/dar-clojure/container>
The key idea is to keep there all sort of things, not just connection 
strings, 
but response objects, parsed request body, user identity, authorization 
checks, etc. 
Hence we

   1. support multiple runtime levels. That is while container itself is 
   just a flat map from keys to computation definitions, 
   you can, for example, mark db connection as an :app level, 
   so it will be cached on `:app` level and will not be recomputed for each 
   request. 
   You can have as many levels as you want.
   
   2.  do all computations asynchronously, i.e. in non-blocking manner. 
   This doesn't result in heavy dependencies or API complications.
    If asynchrony is not your concern you can forget about this.


Below is an example of how it might look in practice

; Lets start with authorization module
(application authorization)
(define :user-id
  :args [:request]
  :fn (fn [req]
        (get-coockie req :auth)))
(define :user
  :args [:user-id :db]
  :fn (fn [id, db]
        (-> db :users id)))
(define :auth!
  :args [:user]
  :fn (fn [user]
        (when-not user
          (throw (ex-send 401)))))
; Now, let's define basic/system things
(application web)
(define :db
  :level :app
  :close #(.close %)
  :fn #(open "db://host:1234"))
(define :max-request-body (* 10 1024 1024))
(define :body
  :args [:request :max-request-body]
  :fn (fn [req max-len]
        (parse (:body req) max-len)))
; We are ready for a user land application
(application my-cool-app)
(include web)(include authorization)
(define :do-something-good-for-your-user
  :pre [:auth!]
  :args [:body]
  :fn (fn [opts]
        (do-good opts)))
; bootstraping (mostly pseudo-code)
(def app (start my-cool-app))
(defn handler [req]
  (let [app (start app {:request req})]
    (try
      (evaluate app :do-something-good-for-your-user)
      (finally
        (stop! app)))))
(start-server handler)

Despite we defined our application with some fancy API, effectivly we just 
built a plain clojure map. 
Its structure is a part of contract, you can deal with it directly via core 
functions.

It seems, that dar.container apps can be a particulary good way to share 
ready to use peaces of functionality, templates, skeletons, etc. 
They have clear concise structure and can be easily patched to accommodate 
concrete needs. 
Simple web framework is to come.

Hope, you will find it useful.

This project was initially inspired by The-Kiln 
<https://github.com/straszheimjeffrey/The-Kiln> and nailed down in easy-app 
<https://github.com/eldargab/easy-app>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to