This commit is contained in:
Jöran Malek 2024-02-26 18:08:18 +01:00
parent b1d3ec73c9
commit 693d12b61c
35 changed files with 389 additions and 269 deletions

View file

@ -1,6 +1,7 @@
using InkForge.Data;
using InkForge.Desktop.Data;
using InkForge.Desktop.Data.Options;
using InkForge.Desktop.Dock;
using InkForge.Desktop.Managers;
using InkForge.Desktop.Models;
using InkForge.Desktop.ViewModels;
@ -19,13 +20,23 @@ public static class InkForgeServiceCollections
{
services.AddHttpClient();
services.AddScoped<IWorkspaceAccessor, WorkspaceAccessor>();
services.AddScoped<IDbContextFactory<NoteDbContext>, NoteDbContextFactory>();
// Singletons
// - Concrete
services.AddSingleton<DocumentManager>();
services.AddSingleton<WorkspaceFactory>();
services.AddSingleton<WorkspaceManager>();
services.AddSingleton<WorkspacesViewModel>();
// Scoped
// - Concrete
services.AddScoped<LocalWorkspaceOptions>();
services.AddSingleton<LandingViewModel>();
services.AddSingleton<WorkspaceManager>();
// - Service
services.AddScoped<IDbContextFactory<NoteDbContext>, NoteDbContextFactory>();
services.AddScoped<IWorkspaceContext, WorkspaceContext>();
// - Forwarders
services.AddScoped(s => s.GetRequiredService<IWorkspaceContext>().Workspace!);
Locator.CurrentMutable.RegisterViewsForViewModels(typeof(InkForgeServiceCollections).Assembly);

View file

@ -1,5 +1,13 @@
namespace Microsoft.Extensions.DependencyInjection
{
public static class TypeFactory
{
public static T Create<T>(IServiceProvider serviceProvider)
{
return TypeFactory<EmptyArguments, T>.Create(serviceProvider, default);
}
}
public static class TypeFactory<TArguments, T>
where TArguments : IFactoryArguments<TArguments>
{
@ -12,6 +20,13 @@ namespace Microsoft.Extensions.DependencyInjection
}
}
public readonly struct EmptyArguments : IFactoryArguments<EmptyArguments>
{
public static Type[] Types => [];
public static implicit operator object[](in EmptyArguments _) => [];
}
public interface IFactoryArguments<T>
where T : IFactoryArguments<T>
{