IoC+Lazy vs ImportingConstructor

Right now in NG, developing .NET Add-ons is easy as developing Python Add-ons. Appreciate NextGen!


According to your tutorials, there are 2 ways to get VC instance.

One is IoC+Lazy, the other one is ImportingConstructor.

Is there any advantage or disadvantage between them?


Although both of them are easy enough, it seems that IoC+Lazy is easier for me.


Thank you.

The tutorials show you both because either or is up to you and how complicated you want to make your source code. The MEF uses IoC, so it is fine to use both, but don’t get too wild and assume that Lazy and IoC will always get something for you. A constructor is reliable for certain things instead of getting something from an imaginary container that may or may not be a null value. For example, I often use the IoC or Lazy to get handles for services I need to use in methods (service locator vs dependency injection), whereas I mostly use an importing constructor to get a handle for the main application, assign functions to event handlers, and other things that need to be reliable through the object’s life cycle.

Cool, I see. Thank you for you tips!