using System; using System.Windows.Forms; using ApplicationContext; namespace ApplicationContexts { internal static class Program { [STAThread] private static void Main( ) { ApplicationController.Begin( ); } } public class ApplicationController { private static System.Windows.Forms.ApplicationContext _context; private readonly IScreenRegistry registry; public ApplicationController( IScreenRegistry registry ) { this.registry = registry; } public static void Begin( ) { Application.EnableVisualStyles( ); Application.SetCompatibleTextRenderingDefault( false ); _context = new System.Windows.Forms.ApplicationContext( new Form1( ) ); Application.Run( _context ); } public void Render( IScreen screen ) { _context.MainForm.Controls.Add( registry.FindFor( screen ) ); } } public interface IScreen {} public interface IScreenRegistry { Control FindFor( IScreen screen ); } }