Created
October 19, 2014 20:29
-
-
Save Idorobots/4c73c116a3b17f5aeca3 to your computer and use it in GitHub Desktop.
Components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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