Dependency Injection and Flows
A few weeks ago, Andy Fawcett introduced a new open source project via his blog post, Managing Dependency Injection within Salesforce. Since then, I’ve been collaborating with Andy Fawcett and John Daniel on developing new features and use cases for the project.
As more and more developers look to adopt Salesforce DX and modular architectures with unlocked packages, many realize that they need to approach their Salesforce application architectures with different design patterns. Dependency Injection is one of those design patterns that enables loosely coupled components by coding to interfaces and having the concrete implementations provided at runtime, whether through custom metadata configuration or programmatic configuration.
Although most of these design patterns and application architectures surround use cases for Apex, Visualforce, and Lightning Components, the Salesforce platform provides amazing power through its declarative “clicks-not-code” features like Flow and Process Builder, and there’s no reason why those capabilities shouldn’t be considered too.
So I’m happy to announce dependency injection support for executing flows where the flow can be defined in one package and its usage determined dynamically at runtime in another package!
The actual flow’s metadata does not have to be defined in the same package or org where this component that uses the flow resides at compile time. The impact of this de-coupling means I can develop faster in my scratch orgs because I do not need to replicate potentially unrelated dependencies like schema and data that aren't pertinent to the package I'm developing. The flow that will be ran in an Apex class, Visualforce page, or Lightning component is determined at runtime, and whose implementation may very well reside in a separate package.
Head over to my blog to read the full post, see screen shots, code snippets, and more to learn how you can begin leveraging your investment in flows with unlocked packages by using dependency injection.
Many thanks to Andy Fawcett and John Daniel for their inspiration hard work on the force-di project. As well as to Arnab Bose and his team for delivering strong capabilities with Flows and Process Builder.
###
I’m a Salesforce Developer and Technical Leader. Learn more about my passion for Salesforce.com solutions @DouglasCAyers and douglascayers.com.
This is huge! Thank you for sharing!
Love the idea of DI further in Salesforce, can’t wait to try it!