From 7806f2e85dd1132644b4c543ca52b191e4342bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Wed, 24 Aug 2022 09:24:44 +0200 Subject: [PATCH] ExtensionMethods and finetuning --- YouTubeViewers.WPF/App.xaml.cs | 9 ++----- .../Components/YouTubeViewersDetails.xaml | 3 ++- .../Components/YouTubeViewersListing.xaml | 5 +++- .../Components/YouTubeViewersListingItem.xaml | 2 +- .../AddDbContextHostBuilderExtensions.cs | 27 +++++++++++++++++++ YouTubeViewers.WPF/MainWindow.xaml | 4 +-- 6 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 YouTubeViewers.WPF/HostBuilders/AddDbContextHostBuilderExtensions.cs diff --git a/YouTubeViewers.WPF/App.xaml.cs b/YouTubeViewers.WPF/App.xaml.cs index e9243af..4aefd39 100644 --- a/YouTubeViewers.WPF/App.xaml.cs +++ b/YouTubeViewers.WPF/App.xaml.cs @@ -16,6 +16,7 @@ using YouTubeViewers.EntityFramework.Commands; using YouTubeViewers.EntityFramework.Queries; using YouTubeViewers.WPF.Stores; using YouTubeViewers.WPF.ViewModels; +using YouTubeViewers.WPF.HostBuilders; namespace YouTubeViewers.WPF; @@ -27,15 +28,9 @@ public partial class App : Application public App() { _host = Host.CreateDefaultBuilder() + .AddDbContext() .ConfigureServices((context, services) => { - string connectionString = context.Configuration.GetConnectionString("sqlite"); - services.AddSingleton( - new DbContextOptionsBuilder() - .UseSqlite(connectionString) - .Options); - services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/YouTubeViewers.WPF/Components/YouTubeViewersDetails.xaml b/YouTubeViewers.WPF/Components/YouTubeViewersDetails.xaml index 951da39..7104e14 100644 --- a/YouTubeViewers.WPF/Components/YouTubeViewersDetails.xaml +++ b/YouTubeViewers.WPF/Components/YouTubeViewersDetails.xaml @@ -43,7 +43,8 @@ + Text="{Binding UserName}" + TextWrapping="Wrap"/> diff --git a/YouTubeViewers.WPF/Components/YouTubeViewersListing.xaml b/YouTubeViewers.WPF/Components/YouTubeViewersListing.xaml index 3f51eaf..b977be6 100644 --- a/YouTubeViewers.WPF/Components/YouTubeViewersListing.xaml +++ b/YouTubeViewers.WPF/Components/YouTubeViewersListing.xaml @@ -21,7 +21,10 @@ x:Name="border" Background="White" CornerRadius="5"/> - diff --git a/YouTubeViewers.WPF/Components/YouTubeViewersListingItem.xaml b/YouTubeViewers.WPF/Components/YouTubeViewersListingItem.xaml index 8b75c39..2e3ae48 100644 --- a/YouTubeViewers.WPF/Components/YouTubeViewersListingItem.xaml +++ b/YouTubeViewers.WPF/Components/YouTubeViewersListingItem.xaml @@ -18,7 +18,7 @@ - + + { + string connectionString = context.Configuration.GetConnectionString("sqlite"); + services.AddSingleton(new DbContextOptionsBuilder().UseSqlite(connectionString).Options); + services.AddSingleton(); + }); + return hostBuilder; + } + } +} diff --git a/YouTubeViewers.WPF/MainWindow.xaml b/YouTubeViewers.WPF/MainWindow.xaml index 99ea9c1..ef4a580 100644 --- a/YouTubeViewers.WPF/MainWindow.xaml +++ b/YouTubeViewers.WPF/MainWindow.xaml @@ -27,8 +27,8 @@ - - + +