-
Notifications
You must be signed in to change notification settings - Fork 768
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
Dependency Injection Recommendation #312
Comments
I might be misunderstanding what you are trying to do, but it seems to me that you are trying to do the work of the state machine library. Are you planning on representing the states as classes? |
Hi @HenningNT , thanks for the response. Let's say that in State1, we send an email, which means we need an emailsender dependency. Then in State2, we need to write to the database, so we need an ORM dependency. Then in State3, we need to send a text to all recipients, so we need an SMS dependency. I rather not inject all these dependencies at the creation of the state machine, and would instead like them injected at the state instead. I haven't played with the code in a few days, but thinking about it, making each state take a function would probably be the least coupled way to do it. |
This sort of reminds me of the Service Locator pattern, and some would say it's an anti-pattern. |
@HenningNT can I just check my understanding. So lets say you have 50 states and a wide variety of actions that require various dependencies.. Rather than inject all dependencies into the service that wraps the state machine and have all action logic directly in that one class, you'd instead just inject an If this is the kind of pattern you foresee, are you able to share any recommended in proc event pub / sub libraries for .netstandard that allow synchronous handling of messages that one could leverage? |
I'm using something similar as @dazinator proposed. In my Machine.Configure().OnEntryAsync() I'm invoking Callback that is processed outside my Machine class. In this way in my Machine class I have only ILog dependency injected. |
Hi all,
Thanks for the cool SDK! Is there any recommendation on DI best practices?
My goal would be to keep the dependencies on the statemachine kept to a minimum, while giving max flexibility to each trigger to engage in all its needed dependencies.
One idea i have is have 1 dependency that handles all trigger events, and that trigger then has a list of all trigger "handlers" for each state that have their own dependencies.
Would that work? Is there any other ideas?
Thanks!
The text was updated successfully, but these errors were encountered: