Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Created October 19, 2014 20:29
Show Gist options
  • Save Idorobots/4c73c116a3b17f5aeca3 to your computer and use it in GitHub Desktop.
Save Idorobots/4c73c116a3b17f5aeca3 to your computer and use it in GitHub Desktop.
Components
(ns component.core
(:require [com.stuartsierra.component :as component]))
(defrecord AppConfig [file path]
component/Lifecycle
(start [this]
(println "Starting AppConfig!")
this)
(stop [this]
(println "Stopping AppConfig!")
this))
(defn app-config [filename]
(map->AppConfig {:file filename :path filename}))
(defrecord Database [connection config]
component/Lifecycle
(start [this]
(println "Starting Database!")
this)
(stop [this]
(println "Stopping Database!")
this))
(defn database [host port]
(map->Database {:connection {:host host :port port}}))
(defrecord Billing [config]
component/Lifecycle
(start [this]
(println "Starting Billing!")
this)
(stop [this]
(println "Stopping Billing!")
this))
(defn billing []
(map->Billing {}))
(defrecord Payments [config db billing]
component/Lifecycle
(start [this]
(println "Starting Payments!")
this)
(stop [this]
(println "Stopping Payments!")
this))
(defn payments []
(map->Payments {}))
(defn- system [config-file host port]
(component/system-map
:billing (component/using (billing)
{:config :configuration})
:cassandra (component/using (database host port)
{:config :configuration})
:configuration (app-config config-file)
:payments (component/using (payments)
{:config :configuration
:db :cassandra
:billing :billing})))
(defn -main [& args]
(component/start (system "file.cfg" "localhost" 1234)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment