Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IoC/DI frameworks with Smart Client Winform apps: How should I approach this?

I'm starting a new Winforms app, and I intend to use an IoC/DI framework (probably Ninject, but I'm also thinking about StructureMap and LinFu).

It seems like nearly everyone who is using IoC/DI is doing so in a web based environment and have found virtually nothing on using Winforms with it.

I'd like to know if anyone is using IoC/DI with Winforms and what approaches you used to deal with Winforms related issues (for instance, how do you make the container available in various parts of the app, do you use the framework to instantiate your forms, etc..)

If anyone knows of any open source Winforms based projects that use IoC/DI (doesn't matter which framework, I should be able to translate concepts) I would like links to those as well.

EDIT:

Are people just not writing Smart Clients anymore?

EDIT:

If you could point me to some real-world code that uses IoC/DI in a Winforms or even console type application (ie, something that is not Web based) I'd appreciate it.

EDIT:

I've been using Ninject and discovered that Ninject will happily inject an instance of it's common kernel interface if you specify an IKernel constructor parameter. This has been working out pretty well, but I'd still like to hear other approaches people use.

like image 971
Erik Funkenbusch Avatar asked Mar 28 '09 22:03

Erik Funkenbusch


3 Answers

The Microsoft patterns and practices team which maintains the Unity injection container also created the Smart Client - Composite UI Application Block for winforms, which I believe uses Unity. I know the new WPF version called Composite Client Application Guidance (codename Prism) uses Unity

like image 128
bendewey Avatar answered Oct 15 '22 16:10

bendewey


I just recently started writing a new WinForms application from scratch using StructureMap for IoC. I've previously looked at SCSF and CAB, but found those overly complex.

I wrote some fluent APIs on top of StructureMaps registry so our modules can register commands, presenters and views.

From my experience it has been worth the effort in all regards, I would never want to write a WinForms app without using these tools and the highly structured modular approach again.

like image 5
grover Avatar answered Oct 15 '22 16:10

grover


I've written an application for displaying maps from OpenStreetMap vector data (http://wiki.openstreetmap.org/index.php/Kosmos). I developed my own simple MVP framework which uses Windsor Castle as an IoC container. You can download the source code if you're interested, it's currently BSD-licensed.

Right now I'm (slowly) working on a redesign of this framework to be able to generate forms dynamically (instead of using the visual designer). I'm toying with the idea of introducing some kind of a fluent interface for building forms and controls, but I haven't yet come up with an elegant solution for this.

like image 1
Igor Brejc Avatar answered Oct 15 '22 15:10

Igor Brejc