Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сlarify how to use with dependency injection system #1

Open
velios opened this issue Feb 15, 2024 · 2 comments
Open

Сlarify how to use with dependency injection system #1

velios opened this issue Feb 15, 2024 · 2 comments

Comments

@velios
Copy link

velios commented Feb 15, 2024

@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?

@Ramblurr
Copy link

Ramblurr commented Nov 5, 2024

I think this issue raises some good points.

Particularly about not being able to unregister hooks. That's a key feature missing for dev time!

@flyingmachine
Copy link
Contributor

These are indeed very good points! I'm not sure when I'll be able to bring my full attention to them, but I hope to soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants