Merge Common to Desktop
This commit is contained in:
parent
26915defe1
commit
e9c6e14965
40 changed files with 447 additions and 282 deletions
|
|
@ -0,0 +1,33 @@
|
|||
using InkForge.Desktop.Controllers;
|
||||
using InkForge.Desktop.Data;
|
||||
using InkForge.Desktop.Services;
|
||||
using InkForge.Desktop.ViewModels;
|
||||
using InkForge.Data;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using ReactiveUI;
|
||||
|
||||
using Splat;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public static class InkForgeServiceCollections
|
||||
{
|
||||
public static IServiceCollection AddInkForge(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpClient();
|
||||
|
||||
services.AddScoped<IDbContextFactory<NoteDbContext>, NoteDbContextFactory>();
|
||||
services.AddScoped(s => s.GetRequiredService<IDbContextFactory<NoteDbContext>>().CreateDbContext());
|
||||
|
||||
services.AddScoped<WorkspaceContext>();
|
||||
|
||||
services.AddSingleton<LandingViewModel>();
|
||||
services.AddSingleton<WorkspaceController>();
|
||||
|
||||
Locator.CurrentMutable.RegisterViewsForViewModels(typeof(InkForgeServiceCollections).Assembly);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue