-
Notifications
You must be signed in to change notification settings - Fork 0
/
MauiProgram.cs
108 lines (92 loc) · 3.92 KB
/
MauiProgram.cs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#nullable disable
using BigBazar.Services;
using BigBazar.ViewModels;
using BigBazar.Views;
using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;
using SkiaSharp.Views.Maui.Controls.Hosting;
namespace BigBazar
{
/// <summary>
/// The main program class for the Maui application.
/// </summary>
public static class MauiProgram
{
/// <summary>
/// Creates and configures the Maui application.
/// </summary>
/// <returns>The configured Maui application.</returns>
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseSkiaSharp()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("SpaceMono-Regular.ttf", "MonoRegular");
});
ConfigureServices(builder.Services);
ConfigureViewsAndViewModels(builder.Services);
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
/// <summary>
/// Configures the services for the application.
/// </summary>
/// <param name="services">The service collection to configure.</param>
public static void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IAppLogger, AppLogger>();
services.AddSingleton<IDataService, DataService>();
services.AddSingleton<IPathService, PathService>();
services.AddSingleton<IDialogService, DialogService>();
services.AddSingleton<IDeviceOrientationService, DeviceOrientationService>();
services.AddSingleton<IVersionService, VersionService>();
services.AddSingleton<IViewModelFactory, ViewModelFactory>();
}
/// <summary>
/// Configures the views and view models for the application.
/// </summary>
/// <param name="services">The service collection to configure.</param>
public static void ConfigureViewsAndViewModels(IServiceCollection services)
{
services.AddTransient<MainPage>();
services.AddTransient<MainPageViewModel>();
services.AddTransient<LogPage>();
services.AddTransient<LogPageViewModel>();
services.AddTransient<BoxListPage>();
services.AddTransient<BoxListPageViewModel>();
services.AddTransient<BoxPage>();
services.AddTransient<BoxPageViewModel>();
services.AddTransient<CatSelectionPage>();
services.AddTransient<CatSelectionPageViewModel>();
services.AddTransient<CategoryPage>();
services.AddTransient<CategoryPageViewModel>();
services.AddTransient<GalleryPage>();
services.AddTransient<GalleryPageViewModel>();
services.AddTransient<FullScreenPhotoPage>();
services.AddTransient<FullScreenPhotoPageViewModel>();
services.AddTransient<AddBoxPage>();
services.AddTransient<AddBoxPageViewModel>();
services.AddTransient<AboutPage>();
services.AddTransient<AboutPageViewModel>();
services.AddTransient<AreaPage>();
services.AddTransient<AreaPageViewModel>();
}
/// <summary>
/// Gets a service from the application's service provider.
/// </summary>
/// <typeparam name="T">The type of service to get.</typeparam>
/// <returns>The requested service, or null if it could not be found.</returns>
public static T GetServiceHelper<T>()
{
return (T)Application.Current?.Handler?.MauiContext?.Services.GetService(typeof(T));
}
}
}