5 ms·
Because a function is not a contract enough - it doesn't have a strong name at point of injection. But yeah, pure functions should be used way more often.
by hack2017 9y ago
Because a function is not a contract enough - it doesn't have a strong name at point of injection. But yeah, pure functions should be used way more often.
- maxxxxx 9y agoDoes everything need to be dependency injected ? Sometimes it seems this is more important than code that works.
- hack2017 9y agoNo, but you will have extremely hard time finding devs who can mix OOP and func effectively. Mostly it's factory-factory and but-muh-Haskell types.
- SideburnsOfDoom 9y agoYou can inject e.g. a Func<int, int, int> or an IAdder interface. Although they are for the sake of example equivalent, I prefer the latter for several related reasons: it gives the DI container a specific type name to work with and avoids complex setup there, it gives the person reading the code a lot more to work with when trying to understanding what the injected thing is used for, and Func<int, int, int> is very general - not all functions with this signature will be be a useful adder.
- maxxxxx 9y agoAgain, why does everything need to be dependency injected? Why not a simple function that adds two numbers? I see these codebases where everything is abstracted two and three times and I don't understand what this achieves other than adding a ton of complexity for even simple things.
- SideburnsOfDoom 9y agoI haven't seen your codebase so I can't answer if your codebase injects too many things to too few, injects the right things or not. It also depends on how big the codebase is, and how long people are going to continue working on it - i.e. "enterprisy" concerns. But injection is done for testability and flexibility.