Comments (3)
Hey there @gregkerzhner!
Good question. We do not have a solution for this right now. For the most part, we've been passing in the dependencies at each level. We have considered different solutions for "prop drilling", however we have not settled on anything yet.
For passing objects purely on the "View" side, we have ViewEnvironment
. However, we have been hesitant to build something like this at the Workflow
level. The concerns have revolved around testability/maintainability.
from workflow.
If you're still listening, dependency injection is very practical in Workflow. Our Kotlin apps use Dagger like crazy, for example.
It's a little more natural to think about in the Workflow Kotlin API because our PropsT
parameter type is separate from general constructor args. So we put @Inject
on constructors, and use PropsT
for runtime configuration only.
But there's no reason Swift can't work the same way. We didn't break out PropsT
in Kotlin because we're bigger on DI, we did it because Kotlin has nothing like Swift's self types, so we couldn't specialize our equivalent of workflowDidChange
.
To get the same effect in Swift, use the factory pattern when dealing with a child workflow that needs access to services or model objects that the parent should be ignorant of. So a call like this:
return AuthenticationWorkflow(authenticationService: AuthenticationService())
.mapOutput { /* ... */ }
.rendered(in: context)
becomes this:
return authenticationWorkflowFactory.build()
.mapOutput { /* ... */ }
.rendered(in: context)
If you apply changes like that all the way up the call chain, presto, you have achieved DI, and none of the 25 ancestors of this workflow that uses the AuthenticationWorkflow
know anything about its use of AuthenticationService
. Nor of this workflow's use of AuthenticationWorkflow
, since its parent will have called someChildWorkflowFactory.build().rendered(in: context)
.
tl;dr: DI is a pattern, not a framework, and Workflow is very friendly to it out of the box. We have no plans to introduce a service provider mechanism for it.
from workflow.
Keeping this ticket open to serve as the seed of proper documentation on this theme.
from workflow.
Related Issues (20)
- Sonatype releases are broken
- Consider making convenience builder functions inline HOT 1
- Proposal: Introduce `WorkflowUICommon` HOT 3
- Get TracingDiagnosticListener out of the main module, clean up the DiagnosticListener API HOT 1
- Kotlin runtime Flow of renderings should be a StateFlow
- What happened to our site search? HOT 2
- Extract Swift code into dedicated repository and remove from this repo.
- Extract Kotlin code into dedicated repository and remove from this repo.
- Introduce renderWorkflowIn overload for starting from state for tests HOT 2
- Rename master branch to trunk HOT 3
- Kotlin workers are started even if scope is cancelled
- Fix deploy_website script to deploy from extracted repos HOT 1
- Documentation needed for backstacks specifically
- Sinks not working for child workflows HOT 12
- Design a common solution to text editing HOT 1
- Update docs to mention Worker Key
- Production Release
- Fill in Coming Soon pages
- Add an entry to userguide/core-patterns about using PropsT for one-shot workflows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workflow.