Skip to content

Commit 398d888

Browse files
committed
Inject Window
1 parent 7a05c59 commit 398d888

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

DapperSqlGenerator.UI/App.xaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<Application x:Class="SqlGenerator.UI.App"
1+
<Application x:Class="DapperSqlGenerator.UI.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:local="clr-namespace:SqlGenerator.UI"
5-
StartupUri="MainWindow.xaml">
4+
xmlns:local="clr-namespace:SqlGenerator.UI">
65
<Application.Resources>
76

87
</Application.Resources>

DapperSqlGenerator.UI/App.xaml.cs

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System;
73
using System.Windows;
84

95
namespace DapperSqlGenerator.UI
@@ -13,8 +9,25 @@ namespace DapperSqlGenerator.UI
139
/// </summary>
1410
public partial class App : Application
1511
{
12+
public IServiceProvider _serviceProvider { get; private set; }
1613

17-
public new static App Current { get { return (App)Application.Current; } }
14+
protected override void OnStartup(StartupEventArgs e)
15+
{
16+
//Services init
17+
var serviceCollection = new ServiceCollection();
18+
ConfigureServices(serviceCollection);
19+
_serviceProvider = serviceCollection.BuildServiceProvider();
1820

21+
var mainWindows = _serviceProvider.GetRequiredService<MainWindow>();
22+
23+
mainWindows.Show();
24+
25+
}
26+
27+
private void ConfigureServices(IServiceCollection services)
28+
{
29+
//Only one main windows
30+
services.AddSingleton<MainWindow>();
31+
}
1932
}
2033
}

DapperSqlGenerator.UI/DapperSqlGenerator.UI.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
</ItemGroup>
4242
<ItemGroup>
4343
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.4.0" />
44+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
45+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
4446
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
4547
</ItemGroup>
4648
<ItemGroup>

DapperSqlGenerator.sln

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.329
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32901.215
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperSqlGenerator", "DapperSqlGenerator\DapperSqlGenerator.csproj", "{F7F06D33-31B5-4BA3-BDB7-57CA5DD58787}"
77
EndProject

0 commit comments

Comments
 (0)