TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

From dependency injection to dependency rejection

99 pointsby dmitover 8 years ago

8 comments

kornishover 8 years ago
This reminds me a lot of Gary Bernhardt&#x27;s <i>Boundaries</i> talk and the associated idea of &quot;functional core, imperative shell&quot;. For anyone who found this article interesting, you might also like this: <a href="https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;boundaries" rel="nofollow">https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;boundaries</a>
评论 #13571399 未加载
charlieflowersover 8 years ago
Very good article. If you think about it, you will see this pattern in many places. Simply because it is the outcome of emphasizing pure functions.<p>For example, it&#x27;s the heart of the virtual DOM in React. Pure functions create an entirely new (no mutation) virtual DOM, and then something at the &quot;impure boundary&quot; applies this to the actual, messy, mutable DOM of the browser.<p>With a little thought you can probably find several other well-known examples.
obstinateover 8 years ago
It&#x27;s interesting -- this is not what I generally end up using DI for. The point of DI, a lot of the time, is to put seams into the program where you can test units of a limited size. If you don&#x27;t have some way of injecting behavior, you end up having some serious trouble when you have a module that brings together the behavior of many sub-modules (how do you test it?). That&#x27;s something these short code example style articles never seem to capture for me.
评论 #13571457 未加载
评论 #13571298 未加载
daxfohlover 8 years ago
Two things:<p>1. This is overly simplistic. What happens if your IO and logic are by necessity interleaved? Grab X out of DB, grab Y or Z out of DB depending on X&#x27;s value, etc.? The whole thing just reeks of &quot;ideal case&quot;.<p>2. This is overly complex. All that really needs to be said here is &quot;pull out your pure code when possible&quot;. There&#x27;s nothing special about F# to enable that. The logic in &quot;tryAcceptComposition&quot; is just a function calling other functions; you can do that in C# or even C. The only advantage F# adds here is the piping syntax, which to me only serves to make the code more obtuse. But I guess you couldn&#x27;t write a three-part series about a single &quot;extract pure function&quot; op.<p>(This brings up an interesting thought: ReSharper should come up with a way to let you highlight a function and extract the &quot;obviously pure&quot; tidbits automatically).
评论 #13571460 未加载
评论 #13571859 未加载
edemover 8 years ago
The key part about why dependency injection with partial application is not functional:<p>&gt; When you inject impure operations into an F# function, that function becomes impure as well. Dependency injection makes everything impure, which explains why it isn&#x27;t functional.
henriquelimaoover 8 years ago
It seems that in the end the initial function Post(ReservationRequestDto dto) has to call the tryAcceptComposition which has its dependencies hard coded there. So how exactly this solved the issue?<p>If you pass the dependencies as parameters in the tryAcceptComposition function, the Post would have to know its dependencies and we would be back to the initial state.<p>I would like to know the whole example he showed before using this model to see how this scale for more than one function.
JackMorganover 8 years ago
Nice! An alternative is to try something like SimpleMock <a href="http:&#x2F;&#x2F;deliberate-software.com&#x2F;simplemock-unit-test-mocking&#x2F;" rel="nofollow">http:&#x2F;&#x2F;deliberate-software.com&#x2F;simplemock-unit-test-mocking&#x2F;</a> which strikes a balance between useful and easy to test. Also there&#x27;s examples in F# <a href="http:&#x2F;&#x2F;deliberate-software.com&#x2F;f-number-unit-testing&#x2F;" rel="nofollow">http:&#x2F;&#x2F;deliberate-software.com&#x2F;f-number-unit-testing&#x2F;</a>
pmarreckover 8 years ago
More evidence that functional programming is a useful simplification&#x2F;complexity reduction on a number of older paradigms.
评论 #13570460 未加载