-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMauiProgram.cs
More file actions
118 lines (104 loc) · 4.35 KB
/
MauiProgram.cs
File metadata and controls
118 lines (104 loc) · 4.35 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
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
109
110
111
112
113
114
115
116
117
118
using Microsoft.Extensions.Logging;
using Realms;
using SkiaSharp.Views.Maui.Controls.Hosting;
using Taskinator.Services;
using Taskinator.ViewModels;
using Taskinator.Views;
using Mopups.Hosting;
using Taskinator.Helper;
using Taskinator.Models;
using System.Text.Json;
namespace Taskinator
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
ConfigureBuilder(builder);
ConfigureLogging(builder);
ConfigureSecrets();
RegisterServices(builder.Services);
RegisterViewModels(builder.Services);
RegisterViews(builder.Services);
return builder.Build();
}
private static void ConfigureBuilder(MauiAppBuilder builder)
{
builder
.UseMauiApp<App>()
.ConfigureMopups()
.UseSkiaSharp()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("font-awesome-5-free-solid.otf", "FontAwesomeSolid");
fonts.AddFont("font-awesome-5-free-regular.otf", "FontAwesomeRegular");
});
}
private static void ConfigureLogging(MauiAppBuilder builder)
{
#if DEBUG
builder.Logging.AddDebug();
#endif
}
private static async void ConfigureSecrets()
{
// Can only use SetAsync once on windows, otherwise it freezes. So a serializer is used.
AuthCredentials credentials = new AuthCredentials
{
domain = "add_your_domain_here",
clientId = "add_your_client_id_here"
};
// Serialize credentials to JSON
string jsonCredentials = JsonSerializer.Serialize(credentials);
// Store the JSON string in SecureStorage
await SecureStorage.SetAsync("auth_credentials", jsonCredentials);
}
private static void RegisterServices(IServiceCollection services)
{
var realmConfig = new RealmConfiguration("taskinator.db")
{
SchemaVersion = 1,
MigrationCallback = (migration, oldSchemaVersion) =>
{
new RealmMigrationHelper().OnMigration(migration, oldSchemaVersion);
},
IsDynamic = false,
ShouldDeleteIfMigrationNeeded = true
};
// Register RealmConfiguration as singleton
services.AddSingleton(realmConfig);
// Register Realm as scoped or transient
services.AddScoped<Realm>(provider => Realm.GetInstance(realmConfig));
services.AddSingleton<IConnectivity>(Connectivity.Current);
services.AddScoped<IDatabaseService, DatabaseService>();
services.AddTransient<IDialogService, DialogService>();
services.AddSingleton<IEventService, EventService>();
services.AddTransient<IEventParser, EventParser>();
}
private static void RegisterViewModels(IServiceCollection services)
{
services.AddTransient<AccountPageViewModel>();
services.AddTransient<AddCustomEventPageViewModel>();
services.AddTransient<DayPageViewModel>();
services.AddTransient<MonthPageViewModel>();
services.AddTransient<YearPageViewModel>();
services.AddTransient<SearchPageViewModel>();
services.AddTransient<SettingsPageViewModel>();
services.AddTransient<EditEventPageViewModel>();
}
private static void RegisterViews(IServiceCollection services)
{
services.AddTransient<AccountPageView>();
services.AddTransient<AddCustomEventPageView>();
services.AddTransient<DayPageView>();
services.AddTransient<MonthPageView>();
services.AddTransient<YearPageView>();
services.AddTransient<SearchPageView>();
services.AddTransient<SettingsPageView>();
services.AddTransient<EditEventPageView>();
}
}
}