journal/2021-03-14--13-00-04Z--the_service_pattern.org

This commit is contained in:
Yann Esposito (Yogsototh) 2021-03-20 17:28:40 +01:00
parent d2aa86f0b5
commit ce1bbd1045
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646

View file

@ -2,7 +2,7 @@
#+Author: Yann Esposito
#+Date: [2021-03-14]
- tags :: [[file:2020-06-03--19-49-30Z--programming.org][programming]] [[file:2020-05-26--06-13-41Z--functional_programming.org][functional programming]] [[file:2020-05-26--06-16-14Z--clojure.org][clojure]] [[file:2020-05-26--06-19-53Z--haskell.org][haskell]]
- tags :: [[file:2020-06-03--19-49-30Z--programming.org][programming]] [[file:2020-05-26--06-13-41Z--functional_programming.org][functional programming]] [[file:2020-05-26--06-16-14Z--clojure.org][clojure]] [[file:2020-05-26--06-19-53Z--haskell.org][haskell]] [[file:2021-03-20--17-27-46Z--architecture.org][architecture]]
- source ::
- related :: [[file:2020-12-23--16-50-17Z--effects_system_in_clojure.org][Effects system in Clojure]]
@ -166,21 +166,26 @@ get from this design.
functions during your tests.
#+begin_src clojure
(defprotocol UserService
(get-user [user-id] "returns a user entity from its id"))
(defprotocol UserService
(get-user [user-id] "returns a user entity from its id"))
(defservice user-service
[[:ConfigService get-in-config]
[:StoreService read-entity]]
(init [this context]
(into context
{:raw-db-get-user
(fn [user-id]
(read-entity db-conf user-id))}))
(get-user [this user-id]
((:raw-db-get-user (get-context this)) user-id)))
(defservice user-service
[[:ConfigService get-in-config]
[:StoreService read-entity]]
(init [this context]
(into context
{:raw-db-get-user
(fn [user-id]
(read-entity db-conf user-id))}))
(get-user [this user-id]
((:raw-db-get-user (get-context this)) user-id)))
(defservice stub-user-service
(init [_ context] context)
(get-user [user-id] {:id "fake-user-id" ,,,}))
(defservice stub-user-service
(init [_ context] context)
(get-user [user-id] {:id "fake-user-id" ,,,}))
(def test
(start-app [config-service store-service stub-user-service
my-service]
(test-my-service)))
#+end_src