When following DDD, Clean code, SOLID and best practices, injection and separation between layers is done using an interface.
Let's say I am splitting the app into Presentation, domain and data. I am having services in domain that needs to get data from the data layer.
Most usual approach is to define an interface in the domain, and implement it in the data.
I used this for years, and found this to have too much ceremony and i feel it can be simplified.
So I switched to function injection instead of protocol, this way I am not doing: a) defining the interface, b) implementing the interface, c) implementing the mock in order to unit test, d) implementing a fake version in order to simulate non real database
The disadvantage however is in the IDE not supporting go to reference. But I don't feel this to slow me down, as usually I can either use "find call references" > go jump to my DIContainer and then, jump to exact implementation, or just remember the name of the repository and function.
Source: r/softwarearchitecture · by /u/zellJun1or