瀏覽代碼

Remove AppBuilderBase and generics

Max Katz 2 年之前
父節點
當前提交
c2e00428df

+ 1 - 1
src/Android/Avalonia.Android/AndroidPlatform.cs

@@ -15,7 +15,7 @@ namespace Avalonia
 {
     public static class AndroidApplicationExtensions
     {
-        public static T UseAndroid<T>(this T builder) where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseAndroid(this AppBuilder builder)
         {
             return builder
                 .UseWindowingSubsystem(() => AndroidPlatform.Initialize(), "Android")

+ 1 - 1
src/Android/Avalonia.Android/AvaloniaSplashActivity.cs

@@ -1,6 +1,6 @@
 using Android.OS;
 using AndroidX.AppCompat.App;
-using AndroidX.Lifecycle;
+using Avalonia.Controls;
 
 namespace Avalonia.Android
 {

+ 236 - 3
src/Avalonia.Controls/AppBuilder.cs

@@ -1,4 +1,8 @@
-using Avalonia.Controls;
+using System;
+using System.Diagnostics.CodeAnalysis;
+using System.Reflection;
+using System.Linq;
+using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Platform;
 
 namespace Avalonia
@@ -6,15 +10,244 @@ namespace Avalonia
     /// <summary>
     /// Initializes platform-specific services for an <see cref="Application"/>.
     /// </summary>
-    public sealed class AppBuilder : AppBuilderBase<AppBuilder>
+    public class AppBuilder
     {
+        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>
+        public IRuntimePlatform RuntimePlatform { get; set; }
+
+        /// <summary>
+        /// Gets or sets a method to call the initialize the runtime platform services (e. g. AssetLoader)
+        /// </summary>
+        public Action RuntimePlatformServicesInitializer { get; private set; }
+
+        /// <summary>
+        /// Gets the <see cref="Application"/> instance being initialized.
+        /// </summary>
+        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>
+        public Action? WindowingSubsystemInitializer { get; private set; }
+
+        /// <summary>
+        /// Gets the name of the currently selected windowing subsystem.
+        /// </summary>
+        public string? WindowingSubsystemName { get; private set; }
+
+        /// <summary>
+        /// Gets or sets a method to call the initialize the windowing subsystem.
+        /// </summary>
+        public Action? RenderingSubsystemInitializer { get; private set; }
+
+        /// <summary>
+        /// Gets the name of the currently selected rendering subsystem.
+        /// </summary>
+        public string? RenderingSubsystemName { get; private set; }
+
+        /// <summary>
+        /// Gets or sets a method to call after the <see cref="Application"/> is setup.
+        /// </summary>
+        public Action<AppBuilder> AfterSetupCallback { get; private set; } = builder => { };
+
+
+        public Action<AppBuilder> AfterPlatformServicesSetupCallback { get; private set; } = builder => { };
+        
         /// <summary>
         /// Initializes a new instance of the <see cref="AppBuilder"/> class.
         /// </summary>
         public AppBuilder()
-            : base(new StandardRuntimePlatform(),
+            : this(new StandardRuntimePlatform(),
                 builder => StandardRuntimePlatformServices.Register(builder.ApplicationType?.Assembly))
         {
         }
+        
+        /// <summary>
+        /// Initializes a new instance of the <see cref="AppBuilder"/> class.
+        /// </summary>
+        protected AppBuilder(IRuntimePlatform platform, Action<AppBuilder> platformServices)
+        {
+            RuntimePlatform = platform;
+            RuntimePlatformServicesInitializer = () => platformServices(this);
+        }
+
+        /// <summary>
+        /// Begin configuring an <see cref="Application"/>.
+        /// </summary>
+        /// <typeparam name="TApp">The subclass of <see cref="Application"/> to configure.</typeparam>
+        /// <returns>An <see cref="AppBuilder"/> instance.</returns>
+        public static AppBuilder Configure<TApp>()
+            where TApp : Application, new()
+        {
+            return new AppBuilder()
+            {
+                ApplicationType = typeof(TApp),
+                // Needed for CoreRT compatibility
+                _appFactory = () => new TApp()
+            };
+        }
+
+        /// <summary>
+        /// Begin configuring an <see cref="Application"/>.
+        /// </summary>
+        /// <param name="appFactory">Factory function for <typeparamref name="TApp"/>.</param>
+        /// <typeparam name="TApp">The subclass of <see cref="Application"/> to configure.</typeparam>
+        /// <remarks><paramref name="appFactory"/> is useful for passing of dependencies to <typeparamref name="TApp"/>.</remarks>
+        /// <returns>An <see cref="AppBuilder"/> instance.</returns>
+        public static AppBuilder Configure<TApp>(Func<TApp> appFactory)
+            where TApp : Application
+        {
+            return new AppBuilder()
+            {
+                ApplicationType = typeof(TApp),
+                _appFactory = appFactory
+            };
+        }
+
+        protected AppBuilder Self => this;
+
+        public AppBuilder AfterSetup(Action<AppBuilder> callback)
+        {
+            AfterSetupCallback = (Action<AppBuilder>)Delegate.Combine(AfterSetupCallback, callback);
+            return Self;
+        }
+        
+        
+        public AppBuilder AfterPlatformServicesSetup(Action<AppBuilder> callback)
+        {
+            AfterPlatformServicesSetupCallback = (Action<AppBuilder>)Delegate.Combine(AfterPlatformServicesSetupCallback, callback);
+            return Self;
+        }
+
+        public delegate void AppMainDelegate(Application app, string[] args);
+        
+        public void Start(AppMainDelegate main, string[] args)
+        {
+            Setup();
+            main(Instance!, args);
+        }
+
+        /// <summary>
+        /// Sets up the platform-specific services for the application, but does not run it.
+        /// </summary>
+        /// <returns></returns>
+        public AppBuilder SetupWithoutStarting()
+        {
+            Setup();
+            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 AppBuilder SetupWithLifetime(IApplicationLifetime lifetime)
+        {
+            _lifetime = lifetime;
+            Setup();
+            return Self;
+        }
+        
+        /// <summary>
+        /// Specifies a windowing subsystem to use.
+        /// </summary>
+        /// <param name="initializer">The method to call to initialize the windowing subsystem.</param>
+        /// <param name="name">The name of the windowing subsystem.</param>
+        /// <returns>An <see cref="AppBuilder"/> instance.</returns>
+        public AppBuilder UseWindowingSubsystem(Action initializer, string name = "")
+        {
+            WindowingSubsystemInitializer = initializer;
+            WindowingSubsystemName = name;
+            return Self;
+        }
+
+        /// <summary>
+        /// Specifies a rendering subsystem to use.
+        /// </summary>
+        /// <param name="initializer">The method to call to initialize the rendering subsystem.</param>
+        /// <param name="name">The name of the rendering subsystem.</param>
+        /// <returns>An <see cref="AppBuilder"/> instance.</returns>
+        public AppBuilder UseRenderingSubsystem(Action initializer, string name = "")
+        {
+            RenderingSubsystemInitializer = initializer;
+            RenderingSubsystemName = name;
+            return Self;
+        }
+
+        /// <summary>
+        /// Configures platform-specific options
+        /// </summary>
+        public AppBuilder With<T>(T options)
+        {
+            _optionsInitializers += () => { AvaloniaLocator.CurrentMutable.Bind<T>().ToConstant(options); };
+            return Self;
+        }
+        
+        /// <summary>
+        /// Configures platform-specific options
+        /// </summary>
+        public AppBuilder With<T>(Func<T> options)
+        {
+            _optionsInitializers += () => { AvaloniaLocator.CurrentMutable.Bind<T>().ToFunc(options); };
+            return Self;
+        }
+        
+        /// <summary>
+        /// Sets up the platform-specific services for the <see cref="Application"/>.
+        /// </summary>
+        private void Setup()
+        {
+            if (RuntimePlatformServicesInitializer == null)
+            {
+                throw new InvalidOperationException("No runtime platform services configured.");
+            }
+
+            if (WindowingSubsystemInitializer == null)
+            {
+                throw new InvalidOperationException("No windowing system configured.");
+            }
+
+            if (RenderingSubsystemInitializer == null)
+            {
+                throw new InvalidOperationException("No rendering system configured.");
+            }
+
+            if (_appFactory == null)
+            {
+                throw new InvalidOperationException("No Application factory configured.");
+            }
+
+            if (s_setupWasAlreadyCalled)
+            {
+                throw new InvalidOperationException("Setup was already called on one of AppBuilder instances");
+            }
+
+            s_setupWasAlreadyCalled = true;
+            _optionsInitializers?.Invoke();
+            RuntimePlatformServicesInitializer();
+            RenderingSubsystemInitializer();
+            WindowingSubsystemInitializer();
+            AfterPlatformServicesSetupCallback(Self);
+            Instance = _appFactory();
+            Instance.ApplicationLifetime = _lifetime;
+            AvaloniaLocator.CurrentMutable.BindToSelf(Instance);
+            Instance.RegisterServices();
+            Instance.Initialize();
+            AfterSetupCallback(Self);
+            Instance.OnFrameworkInitializationCompleted();
+        }
     }
 }

+ 0 - 244
src/Avalonia.Controls/AppBuilderBase.cs

@@ -1,244 +0,0 @@
-using System;
-using System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Linq;
-using Avalonia.Controls.ApplicationLifetimes;
-using Avalonia.Platform;
-
-namespace Avalonia.Controls
-{
-    /// <summary>
-    /// Base class for initializing platform-specific services for an <see cref="Application"/>.
-    /// </summary>
-    /// <typeparam name="TAppBuilder">The type of the AppBuilder class itself.</typeparam>
-    public abstract class AppBuilderBase<TAppBuilder> where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
-    {
-        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>
-        public IRuntimePlatform RuntimePlatform { get; set; }
-
-        /// <summary>
-        /// Gets or sets a method to call the initialize the runtime platform services (e. g. AssetLoader)
-        /// </summary>
-        public Action RuntimePlatformServicesInitializer { get; private set; }
-
-        /// <summary>
-        /// Gets the <see cref="Application"/> instance being initialized.
-        /// </summary>
-        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>
-        public Action? WindowingSubsystemInitializer { get; private set; }
-
-        /// <summary>
-        /// Gets the name of the currently selected windowing subsystem.
-        /// </summary>
-        public string? WindowingSubsystemName { get; private set; }
-
-        /// <summary>
-        /// Gets or sets a method to call the initialize the windowing subsystem.
-        /// </summary>
-        public Action? RenderingSubsystemInitializer { get; private set; }
-
-        /// <summary>
-        /// Gets the name of the currently selected rendering subsystem.
-        /// </summary>
-        public string? RenderingSubsystemName { get; private set; }
-
-        /// <summary>
-        /// Gets or sets a method to call after the <see cref="Application"/> is setup.
-        /// </summary>
-        public Action<TAppBuilder> AfterSetupCallback { get; private set; } = builder => { };
-
-
-        public Action<TAppBuilder> AfterPlatformServicesSetupCallback { get; private set; } = builder => { };
-        
-        protected AppBuilderBase(IRuntimePlatform platform, Action<TAppBuilder> platformServices)
-        {
-            RuntimePlatform = platform;
-            RuntimePlatformServicesInitializer = () => platformServices((TAppBuilder)this);
-        }
-
-        /// <summary>
-        /// Begin configuring an <see cref="Application"/>.
-        /// </summary>
-        /// <typeparam name="TApp">The subclass of <see cref="Application"/> to configure.</typeparam>
-        /// <returns>An <typeparamref name="TAppBuilder"/> instance.</returns>
-        public static TAppBuilder Configure<TApp>()
-            where TApp : Application, new()
-        {
-            return new TAppBuilder()
-            {
-                ApplicationType = typeof(TApp),
-                // Needed for CoreRT compatibility
-                _appFactory = () => new TApp()
-            };
-        }
-
-        /// <summary>
-        /// Begin configuring an <see cref="Application"/>.
-        /// </summary>
-        /// <param name="appFactory">Factory function for <typeparamref name="TApp"/>.</param>
-        /// <typeparam name="TApp">The subclass of <see cref="Application"/> to configure.</typeparam>
-        /// <remarks><paramref name="appFactory"/> is useful for passing of dependencies to <typeparamref name="TApp"/>.</remarks>
-        /// <returns>An <typeparamref name="TAppBuilder"/> instance.</returns>
-        public static TAppBuilder Configure<TApp>(Func<TApp> appFactory)
-            where TApp : Application
-        {
-            return new TAppBuilder()
-            {
-                ApplicationType = typeof(TApp),
-                _appFactory = appFactory
-            };
-        }
-
-        protected TAppBuilder Self => (TAppBuilder)this;
-
-        public TAppBuilder AfterSetup(Action<TAppBuilder> callback)
-        {
-            AfterSetupCallback = (Action<TAppBuilder>)Delegate.Combine(AfterSetupCallback, callback);
-            return Self;
-        }
-        
-        
-        public TAppBuilder AfterPlatformServicesSetup(Action<TAppBuilder> callback)
-        {
-            AfterPlatformServicesSetupCallback = (Action<TAppBuilder>)Delegate.Combine(AfterPlatformServicesSetupCallback, callback);
-            return Self;
-        }
-
-        public delegate void AppMainDelegate(Application app, string[] args);
-        
-        public void Start(AppMainDelegate main, string[] args)
-        {
-            Setup();
-            main(Instance!, args);
-        }
-
-        /// <summary>
-        /// Sets up the platform-specific services for the application, but does not run it.
-        /// </summary>
-        /// <returns></returns>
-        public TAppBuilder SetupWithoutStarting()
-        {
-            Setup();
-            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>
-        /// <param name="initializer">The method to call to initialize the windowing subsystem.</param>
-        /// <param name="name">The name of the windowing subsystem.</param>
-        /// <returns>An <typeparamref name="TAppBuilder"/> instance.</returns>
-        public TAppBuilder UseWindowingSubsystem(Action initializer, string name = "")
-        {
-            WindowingSubsystemInitializer = initializer;
-            WindowingSubsystemName = name;
-            return Self;
-        }
-
-        /// <summary>
-        /// Specifies a rendering subsystem to use.
-        /// </summary>
-        /// <param name="initializer">The method to call to initialize the rendering subsystem.</param>
-        /// <param name="name">The name of the rendering subsystem.</param>
-        /// <returns>An <typeparamref name="TAppBuilder"/> instance.</returns>
-        public TAppBuilder UseRenderingSubsystem(Action initializer, string name = "")
-        {
-            RenderingSubsystemInitializer = initializer;
-            RenderingSubsystemName = name;
-            return Self;
-        }
-
-        protected virtual bool CheckSetup => true;
-
-        /// <summary>
-        /// Configures platform-specific options
-        /// </summary>
-        public TAppBuilder With<T>(T options)
-        {
-            _optionsInitializers += () => { AvaloniaLocator.CurrentMutable.Bind<T>().ToConstant(options); };
-            return Self;
-        }
-        
-        /// <summary>
-        /// Configures platform-specific options
-        /// </summary>
-        public TAppBuilder With<T>(Func<T> options)
-        {
-            _optionsInitializers += () => { AvaloniaLocator.CurrentMutable.Bind<T>().ToFunc(options); };
-            return Self;
-        }
-        
-        /// <summary>
-        /// Sets up the platform-specific services for the <see cref="Application"/>.
-        /// </summary>
-        private void Setup()
-        {
-            if (RuntimePlatformServicesInitializer == null)
-            {
-                throw new InvalidOperationException("No runtime platform services configured.");
-            }
-
-            if (WindowingSubsystemInitializer == null)
-            {
-                throw new InvalidOperationException("No windowing system configured.");
-            }
-
-            if (RenderingSubsystemInitializer == null)
-            {
-                throw new InvalidOperationException("No rendering system configured.");
-            }
-
-            if (_appFactory == null)
-            {
-                throw new InvalidOperationException("No Application factory configured.");
-            }
-
-            if (s_setupWasAlreadyCalled && CheckSetup)
-            {
-                throw new InvalidOperationException("Setup was already called on one of AppBuilder instances");
-            }
-
-            s_setupWasAlreadyCalled = true;
-            _optionsInitializers?.Invoke();
-            RuntimePlatformServicesInitializer();
-            RenderingSubsystemInitializer();
-            WindowingSubsystemInitializer();
-            AfterPlatformServicesSetupCallback(Self);
-            Instance = _appFactory();
-            Instance.ApplicationLifetime = _lifetime;
-            AvaloniaLocator.CurrentMutable.BindToSelf(Instance);
-            Instance.RegisterServices();
-            Instance.Initialize();
-            AfterSetupCallback(Self);
-            Instance.OnFrameworkInitializationCompleted();
-        }
-    }
-}

+ 2 - 3
src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs

@@ -200,9 +200,8 @@ namespace Avalonia
 {
     public static class ClassicDesktopStyleApplicationLifetimeExtensions
     {
-        public static int StartWithClassicDesktopLifetime<T>(
-            this T builder, string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose)
-            where T : AppBuilderBase<T>, new()
+        public static int StartWithClassicDesktopLifetime(
+            this AppBuilder builder, string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose)
         {
             var lifetime = new ClassicDesktopStyleApplicationLifetime()
             {

+ 2 - 4
src/Avalonia.Controls/LoggingExtensions.cs

@@ -8,16 +8,14 @@ namespace Avalonia
         /// <summary>
         /// Logs Avalonia events to the <see cref="System.Diagnostics.Trace"/> sink.
         /// </summary>
-        /// <typeparam name="T">The application class type.</typeparam>
         /// <param name="builder">The app builder instance.</param>
         /// <param name="level">The minimum level to log.</param>
         /// <param name="areas">The areas to log. Valid values are listed in <see cref="LogArea"/>.</param>
         /// <returns>The app builder instance.</returns>
-        public static T LogToTrace<T>(
-            this T builder,
+        public static AppBuilder LogToTrace(
+            this AppBuilder builder,
             LogEventLevel level = LogEventLevel.Warning,
             params string[] areas)
-                where T : AppBuilderBase<T>, new()
         {
             Logger.Sink = new TraceLogSink(level, areas);
             return builder;

+ 3 - 3
src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

@@ -134,12 +134,12 @@ namespace Avalonia.DesignerSupport.Remote
            IAvaloniaRemoteTransportConnection ConfigureApp(IAvaloniaRemoteTransportConnection transport, CommandLineArgs args, object obj);
         }
 
-        class AppInitializer<T> : IAppInitializer where T : AppBuilderBase<T>, new()
+        class AppInitializer : IAppInitializer
         {
             public IAvaloniaRemoteTransportConnection ConfigureApp(IAvaloniaRemoteTransportConnection transport,
                 CommandLineArgs args, object obj)
             {
-                var builder = (AppBuilderBase<T>)obj;
+                var builder = (AppBuilder)obj;
                 if (args.Method == Methods.AvaloniaRemote)
                     builder.UseWindowingSubsystem(() => PreviewerWindowingPlatform.Initialize(transport));
                 if (args.Method == Methods.Html)
@@ -191,7 +191,7 @@ namespace Avalonia.DesignerSupport.Remote
             Log($"Obtaining AppBuilder instance from {builderMethod.DeclaringType.FullName}.{builderMethod.Name}");
             var appBuilder = builderMethod.Invoke(null, null);
             Log($"Initializing application in design mode");
-            var initializer =(IAppInitializer)Activator.CreateInstance(typeof(AppInitializer<>).MakeGenericType(appBuilder.GetType()));
+            var initializer =(IAppInitializer)Activator.CreateInstance(typeof(AppInitializer));
             transport = initializer.ConfigureApp(transport, args, appBuilder);
             s_transport = transport;
             transport.OnMessage += OnTransportMessage;

+ 5 - 10
src/Avalonia.Desktop/AppBuilderDesktopExtensions.cs

@@ -5,8 +5,7 @@ namespace Avalonia
 {
     public static class AppBuilderDesktopExtensions
     {
-        public static TAppBuilder UsePlatformDetect<TAppBuilder>(this TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+        public static AppBuilder UsePlatformDetect(this AppBuilder builder)
         {
             var os = builder.RuntimePlatform.GetRuntimeInfo().OperatingSystem;
 
@@ -35,19 +34,15 @@ namespace Avalonia
             return builder;
         }
 
-        static void LoadAvaloniaNative<TAppBuilder>(TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+        static void LoadAvaloniaNative(AppBuilder builder)
              => builder.UseAvaloniaNative();
-        static void LoadWin32<TAppBuilder>(TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+        static void LoadWin32(AppBuilder builder)
              => builder.UseWin32();
 
-        static void LoadX11<TAppBuilder>(TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+        static void LoadX11(AppBuilder builder)
              => builder.UseX11();
 
-        static void LoadSkia<TAppBuilder>(TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+        static void LoadSkia(AppBuilder builder)
              => builder.UseSkia();
     }
 }

+ 3 - 4
src/Avalonia.Dialogs/ManagedFileDialogExtensions.cs

@@ -24,16 +24,15 @@ namespace Avalonia.Dialogs
             }
         }
 
-        public static TAppBuilder UseManagedSystemDialogs<TAppBuilder>(this TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+        public static AppBuilder UseManagedSystemDialogs(this AppBuilder builder)
         {
             builder.AfterSetup(_ =>
                 AvaloniaLocator.CurrentMutable.Bind<IStorageProviderFactory>().ToSingleton<ManagedStorageProviderFactory<Window>>());
             return builder;
         }
 
-        public static TAppBuilder UseManagedSystemDialogs<TAppBuilder, TWindow>(this TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new() where TWindow : Window, new()
+        public static AppBuilder UseManagedSystemDialogs<TWindow>(this AppBuilder builder)
+            where TWindow : Window, new()
         {
             builder.AfterSetup(_ =>
                 AvaloniaLocator.CurrentMutable.Bind<IStorageProviderFactory>().ToSingleton<ManagedStorageProviderFactory<TWindow>>());

+ 2 - 3
src/Avalonia.Headless.Vnc/HeadlessVncPlatformExtensions.cs

@@ -11,11 +11,10 @@ namespace Avalonia
 {
     public static class HeadlessVncPlatformExtensions
     {
-        public static int StartWithHeadlessVncPlatform<T>(
-            this T builder,
+        public static int StartWithHeadlessVncPlatform(
+            this AppBuilder builder,
             string host, int port,
             string[] args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose)
-            where T : AppBuilderBase<T>, new()
         {
             var tcpServer = new TcpListener(host == null ? IPAddress.Loopback : IPAddress.Parse(host), port);
             tcpServer.Start();    

+ 1 - 2
src/Avalonia.Headless/AvaloniaHeadlessPlatform.cs

@@ -94,8 +94,7 @@ namespace Avalonia.Headless
 
     public static class AvaloniaHeadlessPlatformExtensions
     {
-        public static T UseHeadless<T>(this T builder, AvaloniaHeadlessPlatformOptions opts) 
-            where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseHeadless(this AppBuilder builder, AvaloniaHeadlessPlatformOptions opts)
         {
             if(opts.UseHeadlessDrawing)
                 builder.UseRenderingSubsystem(HeadlessPlatformRenderInterface.Initialize, "Headless");

+ 1 - 2
src/Avalonia.Native/AvaloniaNativePlatformExtensions.cs

@@ -6,8 +6,7 @@ namespace Avalonia
 {
     public static class AvaloniaNativePlatformExtensions
     {
-        public static T UseAvaloniaNative<T>(this T builder)
-            where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseAvaloniaNative(this AppBuilder builder)
         {
             builder.UseWindowingSubsystem(() =>
             {

+ 1 - 2
src/Avalonia.ReactiveUI/AppBuilderExtensions.cs

@@ -12,8 +12,7 @@ namespace Avalonia.ReactiveUI
         /// scheduler, an activation for view fetcher, a template binding hook. Remember
         /// to call this method if you are using ReactiveUI in your application.
         /// </summary>
-        public static TAppBuilder UseReactiveUI<TAppBuilder>(this TAppBuilder builder)
-            where TAppBuilder : AppBuilderBase<TAppBuilder>, new() =>
+        public static AppBuilder UseReactiveUI(this AppBuilder builder) =>
             builder.AfterPlatformServicesSetup(_ => Locator.RegisterResolverCallbackChanged(() =>
             {
                 if (Locator.CurrentMutable is null)

+ 1 - 1
src/Avalonia.X11/X11Platform.cs

@@ -303,7 +303,7 @@ namespace Avalonia
     }
     public static class AvaloniaX11PlatformExtensions
     {
-        public static T UseX11<T>(this T builder) where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseX11(this AppBuilder builder)
         {
             builder.UseWindowingSubsystem(() =>
                 new AvaloniaX11Platform().Initialize(AvaloniaLocator.Current.GetService<X11PlatformOptions>() ??

+ 3 - 4
src/Browser/Avalonia.Browser.Blazor/BlazorSingleViewLifetime.cs

@@ -8,14 +8,13 @@ namespace Avalonia.Browser.Blazor;
 [SupportedOSPlatform("browser")]
 public static class WebAppBuilder
 {
-    public static T SetupWithSingleViewLifetime<T>(
-        this T builder)
-        where T : AppBuilderBase<T>, new()
+    public static AppBuilder SetupWithSingleViewLifetime(
+        this AppBuilder builder)
     {
         return builder.SetupWithLifetime(new BlazorSingleViewLifetime());
     }
 
-    public static T UseBlazor<T>(this T builder) where T : AppBuilderBase<T>, new()
+    public static AppBuilder UseBlazor(this AppBuilder builder)
     {
         return builder
             .UseBrowser()

+ 4 - 8
src/Browser/Avalonia.Browser/BrowserSingleViewLifetime.cs

@@ -2,8 +2,6 @@
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using System.Runtime.Versioning;
-using Avalonia.Browser.Skia;
-using Avalonia.Platform;
 
 namespace Avalonia.Browser;
 
@@ -27,9 +25,8 @@ public class BrowserPlatformOptions
 [SupportedOSPlatform("browser")]
 public static class WebAppBuilder
 {
-    public static T SetupBrowserApp<T>(
-        this T builder, string mainDivId)
-        where T : AppBuilderBase<T>, new()
+    public static AppBuilder SetupBrowserApp(
+        this AppBuilder builder, string mainDivId)
     {
         var lifetime = new BrowserSingleViewLifetime();
 
@@ -42,9 +39,8 @@ public static class WebAppBuilder
             .SetupWithLifetime(lifetime);
     }
 
-    public static T UseBrowser<T>(
-        this T builder)
-        where T : AppBuilderBase<T>, new()
+    public static AppBuilder UseBrowser(
+        this AppBuilder builder)
     {
         return builder
             .UseWindowingSubsystem(BrowserWindowingPlatform.Register)

+ 13 - 17
src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Diagnostics;
 using System.Threading;
+using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Controls.Embedding;
@@ -12,11 +13,9 @@ using Avalonia.LinuxFramebuffer.Input;
 using Avalonia.LinuxFramebuffer.Input.EvDev;
 using Avalonia.LinuxFramebuffer.Input.LibInput;
 using Avalonia.LinuxFramebuffer.Output;
-using Avalonia.OpenGL;
 using Avalonia.Platform;
 using Avalonia.Rendering;
 using Avalonia.Rendering.Composition;
-using Avalonia.Threading;
 #nullable enable
 
 namespace Avalonia.LinuxFramebuffer
@@ -60,7 +59,7 @@ namespace Avalonia.LinuxFramebuffer
         }
 
 
-        internal static LinuxFramebufferLifetime Initialize<T>(T builder, IOutputBackend outputBackend, IInputBackend? inputBackend) where T : AppBuilderBase<T>, new()
+        internal static LinuxFramebufferLifetime Initialize(AppBuilder builder, IOutputBackend outputBackend, IInputBackend? inputBackend)
         {
             var platform = new LinuxFramebufferPlatform(outputBackend);
             builder.UseSkia().UseWindowingSubsystem(platform.Initialize, "fbdev");
@@ -140,20 +139,17 @@ namespace Avalonia.LinuxFramebuffer
 
 public static class LinuxFramebufferPlatformExtensions
 {
-    public static int StartLinuxFbDev<T>(this T builder, string[] args, string? fbdev = null, double scaling = 1, IInputBackend? inputBackend = default)
-        where T : AppBuilderBase<T>, new() =>
-        StartLinuxDirect(builder, args, new FbdevOutput(fileName: fbdev, format: null) { Scaling = scaling }, inputBackend);
-    public static int StartLinuxFbDev<T>(this T builder, string[] args, string fbdev, PixelFormat? format, double scaling, IInputBackend? inputBackend = default)
-        where T : AppBuilderBase<T>, new() =>
-        StartLinuxDirect(builder, args, new FbdevOutput(fileName: fbdev, format: format) { Scaling = scaling }, inputBackend);
-
-    public static int StartLinuxDrm<T>(this T builder, string[] args, string? card = null, double scaling = 1, IInputBackend? inputBackend = default)
-        where T : AppBuilderBase<T>, new() => StartLinuxDirect(builder, args, new DrmOutput(card) { Scaling = scaling }, inputBackend);
-    public static int StartLinuxDrm<T>(this T builder, string[] args, string? card = null, bool connectorsForceProbe = false, DrmOutputOptions? options = null, IInputBackend? inputBackend = default)
-        where T : AppBuilderBase<T>, new() => StartLinuxDirect(builder, args, new DrmOutput(card, connectorsForceProbe, options), inputBackend);
-
-    public static int StartLinuxDirect<T>(this T builder, string[] args, IOutputBackend outputBackend, IInputBackend? inputBackend = default)
-        where T : AppBuilderBase<T>, new()
+    public static int StartLinuxFbDev(this AppBuilder builder, string[] args, string? fbdev = null, double scaling = 1, IInputBackend? inputBackend = default)
+        => StartLinuxDirect(builder, args, new FbdevOutput(fileName: fbdev, format: null) { Scaling = scaling }, inputBackend);
+    public static int StartLinuxFbDev(this AppBuilder builder, string[] args, string fbdev, PixelFormat? format, double scaling, IInputBackend? inputBackend = default)
+        => StartLinuxDirect(builder, args, new FbdevOutput(fileName: fbdev, format: format) { Scaling = scaling }, inputBackend);
+
+    public static int StartLinuxDrm(this AppBuilder builder, string[] args, string? card = null, double scaling = 1, IInputBackend? inputBackend = default)
+        => StartLinuxDirect(builder, args, new DrmOutput(card) { Scaling = scaling }, inputBackend);
+    public static int StartLinuxDrm(this AppBuilder builder, string[] args, string? card = null, bool connectorsForceProbe = false, DrmOutputOptions? options = null, IInputBackend? inputBackend = default)
+        => StartLinuxDirect(builder, args, new DrmOutput(card, connectorsForceProbe, options), inputBackend);
+
+    public static int StartLinuxDirect(this AppBuilder builder, string[] args, IOutputBackend outputBackend, IInputBackend? inputBackend = default)
     {
         var lifetime = LinuxFramebufferPlatform.Initialize(builder, outputBackend, inputBackend);
         builder.SetupWithLifetime(lifetime);

+ 1 - 2
src/Skia/Avalonia.Skia/SkiaApplicationExtensions.cs

@@ -12,10 +12,9 @@ namespace Avalonia
         /// <summary>
         /// Enable Skia renderer.
         /// </summary>
-        /// <typeparam name="T">Builder type.</typeparam>
         /// <param name="builder">Builder.</param>
         /// <returns>Configure builder.</returns>
-        public static T UseSkia<T>(this T builder) where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseSkia(this AppBuilder builder)
         {
             return builder.UseRenderingSubsystem(() => SkiaPlatform.Initialize(
                 AvaloniaLocator.Current.GetService<SkiaOptions>() ?? new SkiaOptions()),

+ 1 - 1
src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs

@@ -16,7 +16,7 @@ namespace Avalonia
 {
     public static class Direct2DApplicationExtensions
     {
-        public static T UseDirect2D1<T>(this T builder) where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseDirect2D1(this AppBuilder builder)
         {
             builder.UseRenderingSubsystem(Direct2D1.Direct2D1Platform.Initialize, "Direct2D1");
             return builder;

+ 1 - 3
src/Windows/Avalonia.Win32/Win32Platform.cs

@@ -26,9 +26,7 @@ namespace Avalonia
 #nullable enable
     public static class Win32ApplicationExtensions
     {
-        public static T UseWin32<T>(
-            this T builder) 
-                where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseWin32(this AppBuilder builder)
         {
             return builder.UseWindowingSubsystem(
                 () => Win32.Win32Platform.Initialize(

+ 1 - 1
src/iOS/Avalonia.iOS/Platform.cs

@@ -12,7 +12,7 @@ namespace Avalonia
 {
     public static class IOSApplicationExtensions
     {
-        public static T UseiOS<T>(this T builder) where T : AppBuilderBase<T>, new()
+        public static AppBuilder UseiOS(this AppBuilder builder)
         {
             return builder
                 .UseWindowingSubsystem(iOS.Platform.Register, "iOS")

+ 1 - 1
tests/Avalonia.Base.UnitTests/Media/Fonts/FontFamilyLoaderTests.cs

@@ -117,7 +117,7 @@ namespace Avalonia.Base.UnitTests.Media.Fonts
         private static IDisposable StartWithResources(params (string, string)[] assets)
         {
             var assetLoader = new MockAssetLoader(assets);
-            var services = new TestServices(assetLoader: assetLoader, platform: new AppBuilder().RuntimePlatform);
+            var services = new TestServices(assetLoader: assetLoader, platform: new StandardRuntimePlatform());
             return UnitTestApplication.Start(services);
         }
     }

+ 1 - 13
tests/Avalonia.UnitTests/TestServices.cs

@@ -20,7 +20,7 @@ namespace Avalonia.UnitTests
     {
         public static readonly TestServices StyledWindow = new TestServices(
             assetLoader: new AssetLoader(),
-            platform: new AppBuilder().RuntimePlatform,
+            platform: new StandardRuntimePlatform(),
             renderInterface: new MockPlatformRenderInterface(),
             standardCursorFactory: Mock.Of<ICursorFactory>(),
             theme: () => CreateSimpleTheme(),
@@ -169,16 +169,4 @@ namespace Avalonia.UnitTests
                     y => y.Open() == Mock.Of<IStreamGeometryContextImpl>()));
         }
     }
-
-    public class AppBuilder : AppBuilderBase<AppBuilder>
-    {
-        public AppBuilder()
-            : base(new StandardRuntimePlatform(),
-                  builder => StandardRuntimePlatformServices.Register(builder.Instance?.GetType()
-                      ?.GetTypeInfo().Assembly))
-        {
-        }
-
-        protected override bool CheckSetup => false;
-    }
 }