diff --git a/samples/todoapp/TodoApp.Uno/TodoApp.Uno/App.xaml.cs b/samples/todoapp/TodoApp.Uno/TodoApp.Uno/App.xaml.cs index 1bee783..672e1a0 100644 --- a/samples/todoapp/TodoApp.Uno/TodoApp.Uno/App.xaml.cs +++ b/samples/todoapp/TodoApp.Uno/TodoApp.Uno/App.xaml.cs @@ -8,6 +8,10 @@ namespace TodoApp.Uno; public partial class App : Application { + protected Window? MainWindow { get; private set; } + public IHost? Host { get; private set; } + private Lazy dbConnection = new(() => CreateSqliteConnection()); + /// /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). @@ -15,22 +19,20 @@ public partial class App : Application public App() { this.InitializeComponent(); - - } - protected Window? MainWindow { get; private set; } - public IHost? Host { get; private set; } + private SqliteConnection DbConnection { get => dbConnection.Value; } - private SqliteConnection dbConnection; + private static SqliteConnection CreateSqliteConnection() + { + SqliteConnection conn = new SqliteConnection("Data Source=:memory:"); + conn.Open(); + return conn; + } protected async override void OnLaunched(LaunchActivatedEventArgs args) { AppContext.SetSwitch("System.Reflection.NullabilityInfoContext.IsSupported", true); - - this.dbConnection = new SqliteConnection("Data Source=:memory:"); - this.dbConnection.Open(); - var builder = this.CreateBuilder(args) // Add navigation support for toolkit controls such as TabBar and NavigationView .UseToolkitNavigation() @@ -42,12 +44,9 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args) .ConfigureServices((context, services) => { - // TODO: Register your services - //services.AddSingleton(); - services.AddDbContext(options => options.UseSqlite(this.dbConnection)); + services.AddDbContext(options => options.UseSqlite(DbConnection)); services.AddScoped(); services.AddTransient(); - }) .UseNavigation(RegisterRoutes) ); @@ -58,14 +57,10 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args) #endif MainWindow.SetWindowIcon(); - // We have to build here so that the services are initialized and we can call InitializeDatabase - // before navigating. This enables us to load the data when the page is loaded Host = builder.Build(); InitializeDatabase(); - // We still make this navigation call so we use the Uno Navigation extension, which automatically wires - // up view models with their page using the ViewMap and RouteMap below. Host = await builder.NavigateAsync(); } diff --git a/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Database/OfflineClientEntity.cs b/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Database/OfflineClientEntity.cs index cf244bf..f430b2e 100644 --- a/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Database/OfflineClientEntity.cs +++ b/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Database/OfflineClientEntity.cs @@ -13,7 +13,7 @@ namespace TodoApp.Uno.Database; public abstract class OfflineClientEntity { [System.ComponentModel.DataAnnotations.Key] - public string Id { get; set; } + public string Id { get; set; } = Guid.NewGuid().ToString("N"); public DateTimeOffset? UpdatedAt { get; set; } public string? Version { get; set; } public bool Deleted { get; set; } diff --git a/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Views/TodoListPage.xaml.cs b/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Views/TodoListPage.xaml.cs index 5b1529f..c991e16 100644 --- a/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Views/TodoListPage.xaml.cs +++ b/samples/todoapp/TodoApp.Uno/TodoApp.Uno/Views/TodoListPage.xaml.cs @@ -29,8 +29,6 @@ public TodoListPage() DataContextChanged += DataContextChangedHandler; } - - // on loaded override private async void DataContextChangedHandler(object sender, DataContextChangedEventArgs e) { @@ -42,7 +40,7 @@ private async void DataContextChangedHandler(object sender, DataContextChangedEv } } - internal void PublishNotification(object sender, NotificationEventArgs args) + internal void PublishNotification(object? sender, NotificationEventArgs args) { Notification notification = new() { diff --git a/samples/todoapp/TodoApp.Uno/global.json b/samples/todoapp/TodoApp.Uno/global.json index a4fc6b1..97ea8ef 100644 --- a/samples/todoapp/TodoApp.Uno/global.json +++ b/samples/todoapp/TodoApp.Uno/global.json @@ -1,16 +1,4 @@ { - // To update the version of Uno please update the version of the Uno.Sdk here. See https://aka.platform.uno/upgrade-uno-packages for more information. - // Bumped from 5.6.54 (-> Uno.WinUI 5.6.99) to 6.5.36 (-> Uno.WinUI 6.5.237). See #524: - // this major-version bump resolves the NU1903 (Tmds.DBus 0.16.0, GHSA-xrw6-gwf8-vvr9) advisory - // on the desktop head for free - Uno.WinUI.Runtime.Skia.X11 switches to the patched - // Tmds.DBus.Protocol dependency starting at Uno.WinUI 6.0.465, and 6.5.237 resolves well above - // that floor. It also lifts the Uno.Wasm.Bootstrap net9.0+ TargetFramework guard blocking the - // browserwasm head (Uno.Sdk 6.x implicitly resolves Uno.Wasm.Bootstrap 10.0.96 instead of the - // 5.x line's 8.0.23). See https://platform.uno/docs/articles/migrating-to-uno-6.html for the - // accompanying manual code changes required across heads (Platforms/Desktop/Program.cs, - // Platforms/Android/Main.Android.cs). - // See https://github.com/CommunityToolkit/Datasync/issues/506 and - // https://github.com/CommunityToolkit/Datasync/issues/524. "msbuild-sdks": { "Uno.Sdk": "6.5.36" },