Adds startup preperations

This commit is contained in:
Serraniel 2023-08-01 21:26:57 +02:00
parent 150f4d7ebe
commit 5557ecb53c
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
11 changed files with 100 additions and 16 deletions

View file

@ -0,0 +1,18 @@
namespace Tagashi_File_Hub.App.Abstractions;
internal class AppBuilder
{
private List<IStartStep> StartSteps { get; } = new();
public AppBuilder WithStartStep(IStartStep step)
{
StartSteps.Add(step);
return this;
}
public AppBuilder WithStartStep(Func<Task> step)
{
return WithStartStep(new DelegateStartStep(step));
}
}

View file

@ -0,0 +1,16 @@
namespace Tagashi_File_Hub.App.Abstractions;
internal class DelegateStartStep : IStartStep
{
private readonly Func<Task> _asyncDelegate;
public DelegateStartStep(Func<Task> asyncDelegate)
{
_asyncDelegate = asyncDelegate;
}
public async Task RunAsync()
{
await _asyncDelegate().ConfigureAwait(false);
}
}

View file

@ -0,0 +1,5 @@
namespace Tagashi_File_Hub.App.Abstractions;
internal interface IApp
{
}

View file

@ -0,0 +1,6 @@
namespace Tagashi_File_Hub.App.Abstractions;
internal interface IStartStep
{
public Task RunAsync();
}

View file

@ -0,0 +1,5 @@
namespace Tagashi_File_Hub.App;
internal class AppStarter
{
}

View file

@ -1,6 +1,6 @@
namespace Tagashi_File_Hub
{
partial class Form1
partial class MainForm
{
/// <summary>
/// Required designer variable.
@ -28,7 +28,7 @@
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
SuspendLayout();
//
// Form1

View file

@ -1,8 +1,8 @@
namespace Tagashi_File_Hub;
public partial class Form1 : Form
public partial class MainForm : Form
{
public Form1()
public MainForm()
{
InitializeComponent();
}

View file

@ -1,17 +1,31 @@
namespace Tagashi_File_Hub
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Tagashi_File_Hub;
internal static class Program
{
internal static class Program
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var hostBuilder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
services.AddSingleton<MainForm>();
});
using var host = hostBuilder.Build();
var serviceProvider = host.Services;
var mainForm = serviceProvider.GetService<MainForm>();
Application.Run(mainForm);
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tagashi_File_Hub
{
internal class Startup
{
}
}

View file

@ -51,8 +51,16 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TagashiFileHub.Core\TagashiFileHub.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="App\Abstractions\Attributes\" />
</ItemGroup>
</Project>