I very recently have hit a brick wall when I gave a shot at Ninject in the project I'm working on.
I have went through all kind of questions, systematically requestionning my design and architecture in favour of dependency injection.
Is this right to inject the container/kernel to the main application presenter?
How to configure Ninject to use along with NHibernate in WinForms?
Conditional dependency injection binding only when property not null
What did I get wrong, DI or Design, and how should I go about it?
After hours, and hours, and hours of searching, I came across that article from Justin Etheredge who speaks of his static DIFactory class.
I now wonder, is it not making things work like magic using a static DI factory?
I'd like to hear pros and cons of using a static DI factory in a real-world application.
Also, are IoC and DI the same, or are they very similar, though some differences?
A static DI Factory is a Service Locator, and a Service Locator is an anti-pattern because it will make it difficult to reason about your code:
The only advantage of Service Locator is that it's slightly easier to understand than Dependency Injection. However, DI isn't that hard to grasp once you get over a few conceptual hurdles.
The relationship between IoC and DI is that DI is a special case of IoC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With