Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created January 29, 2019 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bltavares/a527fcb386f3a8733194ce0c3af0da24 to your computer and use it in GitHub Desktop.
Save bltavares/a527fcb386f3a8733194ce0c3af0da24 to your computer and use it in GitHub Desktop.
(ns playground.core
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"))
(defprotocol Componente
(start! [component])
(stop! [component]))
(defrecord MeuConfig [valores]
Componente
(start! [self]
(println "valores")
(println (:valores self))))
(defrecord S3config [config-atom s3-client]
Componente
(start! [self]
#_(assert! (:s3-client self))
(swap! config-atom {})))
(defrecord DummyConfig []
Componente
(start! [_]
true))
(defrecord FailConfig []
Componente
(start! [self]
(throw (Exception. "Deu ruim"))))
(defn new-s3-config []
(S3config. (atom {})))
(defn usando [component deps]
{:componente component
:deps deps})
(def prod-map {:config (usando (new-s3-config) [:s3-client])
:s3-client (new-s3-client)})
(defn system-start [system-map]
(filter :deps system-map)
(doseq [componente (vals system-map)]
(start! componente)))
(system-start prod-map)
(system-start test-map)
(def test-map {:config (DummyConfig.)})
(def my-comp (S3Config. 1))
(def s3-raw (s3client.))
(def s3-config (start! s3-raw))
(def my-comp-with-config
(assoc my-comp :s3-config s3-config))
(start! my-comp-with-config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment