/* * Original Author: Chris Tomich * Web Site: http://mymemorysucks.com * Released into the public domain on the 2nd August, 2009 6:30PM +8:00 GMT. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace MyMemorySucks.IoCContainer { public partial class IoCContainerUsageExample : Form { private IoCContainer _iocContainer = null; public IoCContainerUsageExample() { InitializeComponent(); // Need to get an instance of the IoCContainer. _iocContainer = IoCContainer.GetInjectionInstance(); // Need to register the IMessageReader interface so that a MyMessageReader object is instantiated when requested using the specified constructor parameters. RegisteredParameter messageContainerParameter = new RegisteredParameter(typeof(MyMessageContainer)); _iocContainer.RegisterComponent(messageContainerParameter); } private void uxClickMe_Click(object sender, EventArgs e) { // Request an instance of an IMessageReader from the IoC container. IMessageReader messageReader = _iocContainer.GetInstance(); uxMessageWindow.Text = messageReader.ReadMessage(); } } }