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

@ -0,0 +1,23 @@
using Microsoft.Extensions.DependencyInjection;
namespace InkForge.Common.ReactiveUI;
public interface IViewModelFactory<T, TCreator>
{
abstract static ObjectFactory<T> CreateObjectFactory();
abstract static TCreator GetCreator(ObjectFactory<T> factory, IServiceProvider serviceProvider);
}
public class ViewModelFactory<T, TFactory, TCreator>
where TFactory : IViewModelFactory<T, TCreator>
where TCreator : Delegate
{
private static ObjectFactory<T>? s_factory;
public TCreator CreateFactory(IServiceProvider serviceProvider)
{
s_factory ??= TFactory.CreateObjectFactory();
return TFactory.GetCreator(s_factory, serviceProvider);
}
}