Dependency Injection RRS feed

  • Question

  • I am trying to use DI in my project (WinForms) using AutoFac. I'm creating an interface for every dependency that I can found and injecting them in the constructor. The problem I am facing right now is I need to refactor all  those classes in my UI layer and pass the interface in their constructors. I spend a lot of time refactoring my code to reflect my changes. 
    How do you deal with this kind of stuff? I have like more than 300 errors now in more than 60 files and changing them is really a pain.

    If you could help me at least to avoid this kind of trouble in the future, that will greatly be appreciated.


    Tuesday, September 4, 2018 5:46 PM

All replies

  • Well, it is what it is for you, becuase you are trying to implement an IoC and DI injection after the fact. If you want to advoid the issues, then you will implement the IoC and DI as you create each class the needs to use DI.

    A lot of the errors usually spin off a couple of main errors. You fix the main errors and lot of the other errors go away. 

    Tuesday, September 4, 2018 7:05 PM
  • Those errors won't just go away that easy because those are instance classes and all of them are asking for the interface to be pass in their constructors. I guess <g class="gr_ gr_147 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="147" id="147">i</g> need to live with it and learn from it.

    Thanks for the help.

    Wednesday, September 5, 2018 3:56 AM
  • Hi Dikong42,

    If you could not fix the error, could you provide some of them for us to test?

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, September 18, 2018 8:51 AM