| 
					
				 | 
			
			
				@@ -18,7 +18,9 @@ namespace Avalonia.Controls 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private static bool s_setupWasAlreadyCalled; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private Action _optionsInitializers; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private Func<Application> _appFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private IApplicationLifetime _lifetime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// Gets or sets the <see cref="IRuntimePlatform"/> instance. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// </summary> 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,10 +32,15 @@ namespace Avalonia.Controls 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public Action RuntimePlatformServicesInitializer { get; private set; } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// Gets or sets the <see cref="Application"/> instance being initialized. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// Gets the <see cref="Application"/> instance being initialized. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        public Application Instance { get; protected set; } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public Application Instance { get; private set; } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// Gets the type of the Instance (even if it's not created yet) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public Type ApplicationType { get; private set; } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// Gets or sets a method to call the initialize the windowing subsystem. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// </summary> 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -76,20 +83,11 @@ namespace Avalonia.Controls 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public static TAppBuilder Configure<TApp>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             where TApp : Application, new() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return Configure(new TApp()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// Begin configuring an <see cref="Application"/>. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <returns>An <typeparamref name="TAppBuilder"/> instance.</returns> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        public static TAppBuilder Configure(Application app) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            AvaloniaLocator.CurrentMutable.BindToSelf(app); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return new TAppBuilder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Instance = app, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ApplicationType = typeof(TApp), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // Needed for CoreRT compatibility 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                _appFactory = () => new TApp() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -157,6 +155,18 @@ namespace Avalonia.Controls 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return Self; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// Sets up the platform-specific services for the application and initialized it with a particular lifetime, but does not run it. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// <param name="lifetime"></param> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /// <returns></returns> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public TAppBuilder SetupWithLifetime(IApplicationLifetime lifetime) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            _lifetime = lifetime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Setup(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return Self; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// Specifies a windowing subsystem to use. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// </summary> 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -254,11 +264,6 @@ namespace Avalonia.Controls 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private void Setup() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (Instance == null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                throw new InvalidOperationException("No App instance configured."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (RuntimePlatformServicesInitializer == null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 throw new InvalidOperationException("No runtime platform services configured."); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -282,6 +287,9 @@ namespace Avalonia.Controls 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             s_setupWasAlreadyCalled = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             _optionsInitializers?.Invoke(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             RuntimePlatformServicesInitializer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Instance = _appFactory(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Instance.ApplicationLifetime = _lifetime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AvaloniaLocator.CurrentMutable.BindToSelf(Instance); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             WindowingSubsystemInitializer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             RenderingSubsystemInitializer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AfterPlatformServicesSetupCallback(Self); 
			 |