Bootstrapping Goodness

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<SomeStructureMapRegistry>());
        this.container.Inject(this.container);

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

        this.attachErrorHandling();

        var context = this.container.GetInstance<AppContext>();
        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());
    }

Leave a Reply