I know interfaces cannot define constructors. What is the best practice to force all classes implementing an interface, to receive their dependencies in a uniform contract. I know ints possible to inject dependencies into objects via properties, but passing them via constructors makes more sense to me. How to DI then ?
I know interfaces cannot define constructors. What is the best practice to force all
Share
We all know this is possible by many different methods, but something that makes sense is more welcome surely. I defined some
set-onlyproperties, then the object is responsible to holding a reference to what is passed to it:This way every class implementing the interface knows that the
set-onlyproperty is a dependency injection, sinceset-onlyproperties are rarely used. I’m not sure if this method is known as agood practiceor not, but for me it is, from now.