Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
1  
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
1  
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
1  
1  
@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

1 Answer 1

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
1  
The MVP pattern is what I've used for my WinForm apps. –  jfrankcarr Jan 26 '12 at 22:25

Your Answer

 
discard

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.