-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathAppHostBuilderExtensions.cs
More file actions
53 lines (48 loc) · 2.36 KB
/
AppHostBuilderExtensions.cs
File metadata and controls
53 lines (48 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Maui.Hosting;
namespace Microsoft.Maui.Controls.Hosting;
public static partial class AppHostBuilderExtensions
{
/// <summary>
/// Configures the <see cref="MauiAppBuilder"/> to use the specified <typeparamref name="TApp"/> as the main application type.
/// </summary>
/// <typeparam name="TApp">The type to use as the application.</typeparam>
/// <param name="builder">The <see cref="MauiAppBuilder"/> to configure.</param>
/// <returns>The configured <see cref="MauiAppBuilder"/>.</returns>
public static MauiAppBuilder UseMauiApp<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApp>(this MauiAppBuilder builder)
where TApp : class, IApplication
{
builder.UseMauiPrimaryApp<TApp>();
builder.SetupXamlDefaults();
return builder;
}
/// <summary>
/// Configures the <see cref="MauiAppBuilder"/> to use the specified <typeparamref name="TApp"/> as the main application type.
/// </summary>
/// <typeparam name="TApp">The type to use as the application.</typeparam>
/// <param name="builder">The <see cref="MauiAppBuilder"/> to configure.</param>
/// <param name="implementationFactory">A factory to create the specified <typeparamref name="TApp"/> using the services provided in a <see cref="IServiceProvider"/>.</param>
/// <returns>The configured <see cref="MauiAppBuilder"/>.</returns>
public static MauiAppBuilder UseMauiApp<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TApp>(this MauiAppBuilder builder, Func<IServiceProvider, TApp> implementationFactory)
where TApp : class, IApplication
{
builder.UseMauiPrimaryApp<TApp>(implementationFactory);
builder.SetupXamlDefaults();
return builder;
}
/// <summary>
/// Registers the .NET MAUI Controls handlers with the handlers collection.
/// </summary>
/// <param name="handlersCollection">The handlers collection to register handlers with.</param>
/// <returns>The handlers collection for chaining.</returns>
public static IMauiHandlersCollection AddMauiControlsHandlers(this IMauiHandlersCollection handlersCollection) =>
handlersCollection.AddControlsHandlers();
static MauiAppBuilder SetupXamlDefaults(this MauiAppBuilder builder)
{
#if WINDOWS || ANDROID || IOS || MACCATALYST || TIZEN
DependencyService.Register<Xaml.ValueConverterProvider>();
#endif
return builder;
}
}