Skip to content

Сlarify how to use with dependency injection system  #1

Description

@velios

@flyingmachine Can you confirm or correct my assumptions? For example, I have a system.

(ns donut.examples.sample-system
  (:require [donut.system :as ds]))

(def system
  {::ds/defs
   {:app {} ;; app modules here

    :side-effects-providers
    {:writer #::ds{:start  (fn []
                             (let [file-writer (file-writer-instance/create)]
                               (file-writer-instance/set-writer-hooks file-writer)
                               file-writer))
                    :stop   (fn [{:keys [::ds/instance]}]
                              (stop-writer-instance instance))
                    :config {}}}}})

;; file-writer-instanse ns
(defn set-writer-hooks
  [file-writer]
  (hooked/register-handler :file-writer/write
                           (fn [{:keys [file-writer text]}]
                             (file-writer-write-fn file-writer text))))

;; somewhere else
(hooked/call :file-writer/write {:file-writer file-writer-from-system
                                 :text "some-text"})

I couldn't come up with a good example. But did I understand correctly that when I have a production system, I initialize hooks in component start section? And when I have a test system, I simply do not initialize the hooks and all side effects associated with this component stop working. Or is it better to initialize hooks in a separate virtual component? I can’t wrap my head around the whole idea, maybe you’ve thought about this and can share?

I also came up with the idea that since we do not indicate in which storage the hooks are contained, then we cannot clear them in the component's stopping loop. This means that if we abandoned some hook during replay development and rebooted the system, then we do not have the opportunity to clean up the hooks associated with this component in order to reinitialize them again? Usually side effects in systems are associated with some component, is it worth managing them separately for each component or how to bypass this issue?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions