View Full Version : Populate Dictionary?
ErikHR
07-06-2007, 06:11 PM
I have the following interface and I am not sure you to use spring to set the items?
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
interface ISelectionAdapter {
Dictionary<string, System.Windows.Forms.Control> Controls { get; set; }
}
Thanks,
Erik
Mark Pollack
07-07-2007, 12:54 AM
Hi Erik,
Here is how you could configure that property
<object name="userControl1" type="Spring.WindowsControlLibrary.UserControl1, Spring.WindowsControlLibrary"
lazy-init="true">
</object>
<object name="userControl2" type="Spring.WindowsControlLibrary.UserControl2, Spring.WindowsControlLibrary"
lazy-init="true">
</object>
<object name="selectionAdapter" type="Spring.IocQuickStart.Selection.SelectionAdapter, Spring.IocQuickStart.AppContext"
lazy-init="true">
<property name="Controls">
<dictionary key-type="string" value-type="System.Windows.Forms.Control, System.Windows.Forms">
<entry key="userControl1" value-ref="userControl1"/>
<entry key="userControl2" value-ref="userControl2"/>
</dictionary>
</property>
</object>
There is some documentation on configuring how to wire up generic collection in the ref doc here (http://www.springframework.net/doc-latest/reference/html/objects.html#objects-generic-collections-values). I used lazy-init = true so the controls aren't created until you ask for the selection adapter from the container.
You may also be interested in recent work to allow for 'transparent' dependency injection for winforms, take a look at the Winform forum for more information.
Cheers,
Mark
ErikHR
07-07-2007, 06:25 PM
Mark,
Thanks for the help. That is just what I needed.
How do I set the .Dock property of the control to Fill using the DockStyle.Fill enum?
If I want to have one control subscribe to another controls event (maybe the load event) How would I use spring to do this?
Thanks,
Erik
Mark Pollack
07-07-2007, 07:30 PM
Hi Erik,
Spring will rely on the standard .NET type converters to convert from a string to an enum, but you can also register custom converters to override that behavior. In the case of the Dock enum, the standard converter works fine and all you have to do is the following
<object name="userControl1" type="Spring.WindowsControlLibrary.UserControl1, Spring.WindowsControlLibrary" lazy-init="true">
<property name="Dock" value="Fill"/>
</object>
Some more info is here (http://www.springframework.net/doc-latest/reference/html/objects.html#objects-type-conversion-enums). There is at the moment some undocumented support for wiring of events, but it is not as complete as I would like and I am considering removing it for the 1.1 release. I'll make a seperate post on that at the moment, in order to get some of your feedback, but I'd recommend doing the event registration in code for now.
Cheers,
Mark
Huoliuhi
09-29-2008, 03:11 PM
I'm going to bump the tread up.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.