0

Bit of a noob question here for asp net core 2.2 Using the built in dependency injection. I understand how to inject a dependency into a class in a simple use case however if I have a slightly more complex case I am getting lost So Class A needs to call a method in Class B which has a dependency injected via constructor. So now I am stuck instantiating class B inside Class A as it requires the dependency to instantiate. Clearly I am missing something obvious!

Graeme
  • 46
  • 4
  • You should inject Class B into the constructor of Class A, not instantiate directly. Could you update your question to include the code that is giving you problems? – devNull May 03 '20 at 23:07
  • As @devNull said you are unlikely actually need to call constructor... But in rare case you just add dependency on "factory" - strategy pattern is one common case where you need to construct objects rather than take dependency on them - see duplicate for details (non container specific, but there really nothing special there) – Alexei Levenkov May 03 '20 at 23:12

0 Answers0