8000 Documentation: Revision of Dependency Injection Section by khajavi · Pull Request #7276 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Documentation: Revision of Dependency Injection Section #7276

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

Merged
merged 8 commits into from
Sep 2, 2022

Conversation

khajavi
Copy link
Member
@khajavi khajavi commented Aug 29, 2022

Following this work, here is another PR that explains DI in more detail.

@khajavi khajavi requested review from adamgfraser and jdegoes August 29, 2022 14:34
@khajavi khajavi marked this pull request as ready for review August 29, 2022 14:34
Copy link
Contributor
@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can push this even more in the direction of the idiomatic pattern of ZIO services.

Start with some example. We want to implement service X which is implemented in terms of services Y and Z. We want to keep our code nice and modular and testable.

We define interfaces for each service. This gives us the contract for how our services work together and lets us figure out our architecture and divide and conquer.

Create implementations of our services taking their dependencies as constructor parameters. It's just constructor based dependency injection!

Create layers for each of our implementations. This lets ZIO automatically wire them together. It also lets us take care of any setup or teardown. We use ZIO.service to grab things from the environment.

Finally we wire all of our services together with provide. We use ZIO.service once more in our main application to actually access the service that contains our main application logic and call it.

In this version the environment and accessing it is more of the "how" versus the "what".

@khajavi
Copy link
Member Author
khajavi commented Sep 2, 2022

@adamgfraser
Thank you for your comment. I included your notes.

While we have a separate section on "Service Pattern", for the first version of the "Dependency Injection" section, I tried to make these two concepts separate and focus only on the essence of DI.

Although they have overlapping topics, it is better to emphasize the Service Pattern in the DI section as you suggested.

@khajavi khajavi requested a review from adamgfraser September 2, 2022 14:34
@adamgfraser adamgfraser merged commit 78c79ac into zio:series/2.x Sep 2, 2022
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

Successfully merging this pull request may close these issues.

2 participants
0