Factories and Views

This commit is contained in:
Jöran Malek 2024-02-10 10:38:28 +01:00
parent 4e7dfc56a8
commit 2529b728ba
16 changed files with 188 additions and 4 deletions

View file

@ -1,6 +1,7 @@
using InkForge.Common.Controllers;
using InkForge.Common.Data;
using InkForge.Common.ViewModels;
using InkForge.Common.ViewModels.Landing;
using InkForge.Common.Views;
using InkForge.Data;
@ -16,6 +17,8 @@ public static class InkForgeServiceCollections
services.AddDbContextFactory<NoteDbContext, NoteDbContextFactory>();
services.AddSingleton<LandingViewModel>();
services.AddSingleton<LandingViewModelFactory>();
services.AddSingleton<WorkspaceController>();
services.AddTransient<IViewFor<LandingViewModel>, LandingView>();

View file

@ -0,0 +1,22 @@
namespace Microsoft.Extensions.DependencyInjection
{
public static class TypeFactory<TFactory, T>
where TFactory : struct, IObjectParameters<TFactory>
{
private static ObjectFactory<T>? s_objectFactory;
public static T Create(in TFactory factory, IServiceProvider serviceProvider)
{
s_objectFactory ??= ActivatorUtilities.CreateFactory<T>(TFactory.Types);
return s_objectFactory(serviceProvider, (object[])factory);
}
}
public interface IObjectParameters<T>
where T : struct, IObjectParameters<T>
{
abstract static Type[] Types { get; }
abstract static implicit operator object[](in T self);
}
}