Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm coming back into the winform world after being in the web world for a while. Is it common or otherwise feasible for developers to use IoC in winform?

My concern is mainly with performance. I envision that I will need to "bootstrap" or initialize all my inverted items that are required by a given form instance on form initialization. If this initialization becomes expensive, I can push the task off to a thread, but that requires that I get the created objects back to the main thread where they will be used at some point.

share|improve this question
It depends on the developer... some do, some don't. – Oded Jan 26 '12 at 17:57
@Oded - Ok, I should have said "feasible" rather than common. I'm looking to see if I should use IoC at all. You are telling me the concept itself translates to winforms then. In a quick google search I did not find any 3rd party frameworks for IoC geared towards winform. Right now I'm just rolling my own little inverter. – P.Brian.Mackey Jan 26 '12 at 18:00
Correct - there is nothing stopping you from using IoC in winforms. They are much better suited to it than webforms (no static almost unmockable HttpContext and other web baggage). – Oded Jan 26 '12 at 18:02
@P.Brian.Mackey You are completely correct, mixed them up :) What I was trying to say is this: DI doesn't need frameworks - IoC containers do though. :) – Max Jan 26 '12 at 21:40
up vote 6 down vote accepted

It's very common and I can't find many complaints regarding the speed of Unity/Ninject type resolution.

Your classes doing the heaviest lifting that have the most external dependencies you want to inject into should be nowhere near the Windows Forms framework code you're writing and so the fact that you're using Windows Forms shouldn't bare heavily on your decision (look into the MVP pattern for more on decoupling application logic from the types the designer uses).

Chances are those external dependencies you're trying to remove, by using IoC, will be very slow themselves and will be your real bottleneck. In comparison to writing a 100k file or making a web request, it's not even worth thinking about.

share|improve this answer
The MVP pattern is what I've used for my WinForm apps. – jfrankcarr Jan 26 '12 at 22:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.