Adds startup preperations
This commit is contained in:
parent
150f4d7ebe
commit
5557ecb53c
18
src/Tagashi File Hub/App/Abstractions/AppBuilder.cs
Normal file
18
src/Tagashi File Hub/App/Abstractions/AppBuilder.cs
Normal 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));
|
||||
}
|
||||
}
|
16
src/Tagashi File Hub/App/Abstractions/DelegateStartStep.cs
Normal file
16
src/Tagashi File Hub/App/Abstractions/DelegateStartStep.cs
Normal 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);
|
||||
}
|
||||
}
|
5
src/Tagashi File Hub/App/Abstractions/IApp.cs
Normal file
5
src/Tagashi File Hub/App/Abstractions/IApp.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace Tagashi_File_Hub.App.Abstractions;
|
||||
|
||||
internal interface IApp
|
||||
{
|
||||
}
|
6
src/Tagashi File Hub/App/Abstractions/IStartStep.cs
Normal file
6
src/Tagashi File Hub/App/Abstractions/IStartStep.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace Tagashi_File_Hub.App.Abstractions;
|
||||
|
||||
internal interface IStartStep
|
||||
{
|
||||
public Task RunAsync();
|
||||
}
|
5
src/Tagashi File Hub/App/AppStarter.cs
Normal file
5
src/Tagashi File Hub/App/AppStarter.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace Tagashi_File_Hub.App;
|
||||
|
||||
internal class AppStarter
|
||||
{
|
||||
}
|
|
@ -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
|
|
@ -1,8 +1,8 @@
|
|||
namespace Tagashi_File_Hub;
|
||||
|
||||
public partial class Form1 : Form
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
public Form1()
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
12
src/Tagashi File Hub/Startup.cs
Normal file
12
src/Tagashi File Hub/Startup.cs
Normal 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
|
||||
{
|
||||
}
|
||||
}
|
|
@ -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>
|
Loading…
Reference in a new issue