How to not pass around the container when using IoC in Winforms
Posted
by L2Type
on Stack Overflow
See other posts from Stack Overflow
or by L2Type
Published on 2009-11-19T18:46:25Z
Indexed on
2010/05/18
5:51 UTC
Read the original article
Hit count: 396
I'm new to the world of IoC and having a problem with implementing it in a Winforms application. I have an extremely basic application Winform application that uses MVC, it is one controller that does all the work and a working dialog (obviously with a controller). So I load all my classes in to my IoC container in program.cs and create the main form controller using the container. But this is where I am having problems, I only want to create the working dialog controller when it's used and inside a using statement.
At first I passed in the container but I've read this is bad practice and more over the container is a static and I want to unit test this class.
So how do you create classes in a unit test friendly way without passing in the container, I was considering the abstract factory pattern but that alone would solve my problem without using the IoC.
I'm not using any famous framework, I borrowed a basic one from this blog post http://www.kenegozi.com/Blog/2008/01/17/its-my-turn-to-build-an-ioc-container-in-15-minutes-and-33-lines.aspx
How do I do this with IoC? Is this the wrong use for IoC?
© Stack Overflow or respective owner