diff --git a/WinGreedLibrary/DataAccess.cs b/WinGreedLibrary/DataAccess.cs new file mode 100644 index 0000000..d700cf7 --- /dev/null +++ b/WinGreedLibrary/DataAccess.cs @@ -0,0 +1,9 @@ +namespace WpfLibrary; + +public class DataAccess : IDataAccess +{ + public string GetData() + { + return "This is the data from the Data Access class!"; + } +} diff --git a/WinGreedLibrary/IDataAccess.cs b/WinGreedLibrary/IDataAccess.cs new file mode 100644 index 0000000..e60d7f9 --- /dev/null +++ b/WinGreedLibrary/IDataAccess.cs @@ -0,0 +1,7 @@ +namespace WpfLibrary +{ + public interface IDataAccess + { + string GetData(); + } +} \ No newline at end of file diff --git a/WinGreedLibrary/WinGreedLib.csproj b/WinGreedLibrary/WinGreedLib.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/WinGreedLibrary/WinGreedLib.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/WinGreedWPF.sln b/WinGreedWPF.sln new file mode 100644 index 0000000..050145d --- /dev/null +++ b/WinGreedWPF.sln @@ -0,0 +1,71 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinGreedWPF", "WinGreedWPF\WinGreedWPF.csproj", "{09A80A37-40CF-472E-BCBC-B9FA801C06C6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinGreedLib", "WinGreedLibrary\WinGreedLib.csproj", "{65D28463-7B80-4D95-8170-AD17FB456F9F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM.ActiveCfg = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM.Build.0 = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|ARM64.Build.0 = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x64.ActiveCfg = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x64.Build.0 = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x86.ActiveCfg = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Debug|x86.Build.0 = Debug|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|Any CPU.Build.0 = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM.ActiveCfg = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM.Build.0 = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM64.ActiveCfg = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|ARM64.Build.0 = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x64.ActiveCfg = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x64.Build.0 = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x86.ActiveCfg = Release|Any CPU + {09A80A37-40CF-472E-BCBC-B9FA801C06C6}.Release|x86.Build.0 = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM.ActiveCfg = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM.Build.0 = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|ARM64.Build.0 = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x64.ActiveCfg = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x64.Build.0 = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x86.ActiveCfg = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Debug|x86.Build.0 = Debug|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|Any CPU.Build.0 = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM.ActiveCfg = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM.Build.0 = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM64.ActiveCfg = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|ARM64.Build.0 = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x64.ActiveCfg = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x64.Build.0 = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x86.ActiveCfg = Release|Any CPU + {65D28463-7B80-4D95-8170-AD17FB456F9F}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A6F6E52C-F6D0-4B6E-8F50-00FDF6DC3C40} + EndGlobalSection +EndGlobal diff --git a/WinGreedWPF/App.xaml b/WinGreedWPF/App.xaml new file mode 100644 index 0000000..379fbb4 --- /dev/null +++ b/WinGreedWPF/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/WinGreedWPF/App.xaml.cs b/WinGreedWPF/App.xaml.cs new file mode 100644 index 0000000..e48a050 --- /dev/null +++ b/WinGreedWPF/App.xaml.cs @@ -0,0 +1,42 @@ +using WinGreedWPF.StartupHelpers; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System.Windows; +using WpfLibrary; + +namespace WinGreedWPF; + +public partial class App : Application +{ + public static IHost? AppHost { get; private set; } + + public App() + { + AppHost = Host.CreateDefaultBuilder() + .ConfigureServices((hostContext, services) => + { + services.AddSingleton(); + services.AddFormFactory(); + services.AddFormFactory(); + services.AddTransient(); + }) + .Build(); + } + + protected override async void OnStartup(StartupEventArgs e) + { + await AppHost!.StartAsync(); + + var startupForm = AppHost.Services.GetRequiredService(); + startupForm.Show(); + + base.OnStartup(e); + } + + protected override async void OnExit(ExitEventArgs e) + { + await AppHost!.StopAsync(); + base.OnExit(e); + } + +} diff --git a/WinGreedWPF/AssemblyInfo.cs b/WinGreedWPF/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/WinGreedWPF/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/WinGreedWPF/ChildForm.xaml b/WinGreedWPF/ChildForm.xaml new file mode 100644 index 0000000..b1f0252 --- /dev/null +++ b/WinGreedWPF/ChildForm.xaml @@ -0,0 +1,16 @@ + + + + Child Form + + + + diff --git a/WinGreedWPF/ChildForm.xaml.cs b/WinGreedWPF/ChildForm.xaml.cs new file mode 100644 index 0000000..afc7a5e --- /dev/null +++ b/WinGreedWPF/ChildForm.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows; +using WpfLibrary; + +namespace WinGreedWPF; +public partial class ChildForm : Window +{ + private readonly IDataAccess _dataAccess; + + public ChildForm(IDataAccess dataAccess) + { + InitializeComponent(); + _dataAccess = dataAccess; + dataAccessInfo.Text = _dataAccess.GetData(); + } +} diff --git a/WinGreedWPF/ExtraChild.xaml b/WinGreedWPF/ExtraChild.xaml new file mode 100644 index 0000000..95edc70 --- /dev/null +++ b/WinGreedWPF/ExtraChild.xaml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/WinGreedWPF/ExtraChild.xaml.cs b/WinGreedWPF/ExtraChild.xaml.cs new file mode 100644 index 0000000..e8afa98 --- /dev/null +++ b/WinGreedWPF/ExtraChild.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WinGreedWPF +{ + /// + /// Interaction logic for ExtraChild.xaml + /// + public partial class ExtraChild : Window + { + public ExtraChild() + { + InitializeComponent(); + } + } +} diff --git a/WinGreedWPF/MainWindow.xaml b/WinGreedWPF/MainWindow.xaml new file mode 100644 index 0000000..c7b3845 --- /dev/null +++ b/WinGreedWPF/MainWindow.xaml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + N a m n + + + + + + + + + + + diff --git a/WinGreedWPF/MainWindow.xaml.cs b/WinGreedWPF/MainWindow.xaml.cs new file mode 100644 index 0000000..f5bff31 --- /dev/null +++ b/WinGreedWPF/MainWindow.xaml.cs @@ -0,0 +1,54 @@ +using WinGreedWPF.StartupHelpers; +using System.Windows; +using WpfLibrary; + +namespace WinGreedWPF; + +public partial class MainWindow : Window +{ + private readonly IDataAccess _dataAccess; + private readonly IAbstractFactory _factory; + private readonly IAbstractFactory _extraCh; + + public MainWindow(IDataAccess dataAccess, + IAbstractFactory factory, + IAbstractFactory extraCh ) + { + InitializeComponent(); + _dataAccess = dataAccess; + _factory = factory; + _extraCh = extraCh; + } + + private void getData_Click(object sender, RoutedEventArgs e) + { + data.Text=_dataAccess.GetData(); + } + + private void openChildForm_Click(object sender, RoutedEventArgs e) + { + _factory.Create().Show(); + } + + private void openExtraChildForm_Click(object sender, RoutedEventArgs e) + { + _extraCh.Create().Show(); + } + + private void NextPlayer(object sender, RoutedEventArgs e) + { + MessageBox.Show("Nytt spel"); + } + + private void NewPlayer(object sender, RoutedEventArgs e) + { + MessageBox.Show("Ny Spelare"); + NameField.Visibility = Visibility.Visible; + } + + private void NewConfirm(object sender, RoutedEventArgs e) + { + MessageBox.Show($"Ny Spelare {NameField.Text}"); + NameField.Visibility = Visibility.Hidden; + } +} diff --git a/WinGreedWPF/StartupHelpers/AbstractFactory.cs b/WinGreedWPF/StartupHelpers/AbstractFactory.cs new file mode 100644 index 0000000..521dcc9 --- /dev/null +++ b/WinGreedWPF/StartupHelpers/AbstractFactory.cs @@ -0,0 +1,18 @@ +using System; + +namespace WinGreedWPF.StartupHelpers; + +public class AbstractFactory : IAbstractFactory +{ + private readonly Func _factory; + + public AbstractFactory(Func factory) + { + _factory = factory; + } + + public T Create() + { + return _factory(); + } +} diff --git a/WinGreedWPF/StartupHelpers/IAbstractFactory.cs b/WinGreedWPF/StartupHelpers/IAbstractFactory.cs new file mode 100644 index 0000000..70791a4 --- /dev/null +++ b/WinGreedWPF/StartupHelpers/IAbstractFactory.cs @@ -0,0 +1,7 @@ +namespace WinGreedWPF.StartupHelpers +{ + public interface IAbstractFactory + { + T Create(); + } +} \ No newline at end of file diff --git a/WinGreedWPF/StartupHelpers/ServiceExtensions.cs b/WinGreedWPF/StartupHelpers/ServiceExtensions.cs new file mode 100644 index 0000000..aeaec59 --- /dev/null +++ b/WinGreedWPF/StartupHelpers/ServiceExtensions.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using System; + +namespace WinGreedWPF.StartupHelpers; + +public static class ServiceExtensions +{ + public static void AddFormFactory(this IServiceCollection services) + where TForm : class + { + services.AddTransient(); + services.AddSingleton>(x => () => x.GetService()!); + services.AddSingleton, AbstractFactory>(); + } +} diff --git a/WinGreedWPF/WinGreedWPF.csproj b/WinGreedWPF/WinGreedWPF.csproj new file mode 100644 index 0000000..b0eac22 --- /dev/null +++ b/WinGreedWPF/WinGreedWPF.csproj @@ -0,0 +1,19 @@ + + + + WinExe + net6.0-windows + enable + true + + + + + + + + + + + +