Here’s some code from the BootStrapper that I’ve been rather happy with building WinForms apps lately:

public ApplicationContext Initialize()
{
    this.container.Configure(c => c.AddRegistry());
    this.container.Inject(this.container);

    ApplicationSettings settings = new AppSettingsParser().Parse(this.appSettings);
    this.container.Inject(settings);

    this.attachErrorHandling();

    var context = this.container.GetInstance();
    return context;
}

Of course, you use it something like this:

private static void Main()
{

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    Application.Run(new BootStrapper(ConfigurationManager.AppSettings, new Container()).Initialize());
}

Tags: , , ,