Add project files.

This commit is contained in:
Daniel Clark
2022-11-01 15:26:08 +00:00
parent daa7b59f22
commit 7e4f880821
408 changed files with 16863 additions and 0 deletions
@@ -0,0 +1,35 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using TheXamlGuy.Framework.Core;
namespace TheXamlGuy.Framework.WPF
{
public static class IHostBuilderExtensions
{
public static IHostBuilder ConfigureTemplates(this IHostBuilder hostBuilder, Action<ITemplateBuilder> builderDelegate)
{
hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
{
TemplateBuilder? builder = new();
builderDelegate?.Invoke(builder);
serviceCollection
.AddSingleton(builder.Descriptors)
.AddSingleton<ITemplateFactory, TemplateFactory>()
.AddSingleton<INamedTemplateFactory, NamedTemplateFactory>()
.AddSingleton<ITypedDataTemplateFactory, TypedDataTemplateFactory>()
.AddSingleton<INamedDataTemplateFactory, NamedDataTemplateFactory>()
.AddSingleton<ITemplateSelector, TemplateSelector>();
foreach (ITemplateDescriptor? descriptor in builder.Descriptors)
{
serviceCollection.Add(new ServiceDescriptor(descriptor.TemplateType, descriptor.TemplateType, descriptor.Lifetime));
serviceCollection.Add(new ServiceDescriptor(descriptor.DataType, descriptor.DataType, descriptor.Lifetime));
}
});
return hostBuilder;
}
}
}
@@ -0,0 +1,18 @@
using Microsoft.Extensions.DependencyInjection;
using TheXamlGuy.Framework.Core;
namespace TheXamlGuy.Framework.WPF
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddRequiredWpf(this IServiceCollection serviceCollection)
{
return serviceCollection
.AddSingleton<IRoute, Route>()
.AddSingleton<IRouteDescriptorCollection, RouteDescriptorCollection>()
.AddSingleton<IRouterContext, Router>()
.AddTransient<IMediatorHandler<Navigate>, NavigateHandler>()
.RegisterHandlers();
}
}
}
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Reflection;
namespace TheXamlGuy.Framework.WPF
{
public static class ObjectExtensions
{
public static T ToObject<T>(this IDictionary<string, object> source) where T : class, new()
{
T? target = new();
if (target.GetType() is { } targetType)
{
foreach (KeyValuePair<string, object> item in source)
{
if (targetType.GetProperty(item.Key) is PropertyInfo propertyInfo)
{
propertyInfo.SetValue(target, item.Value, null);
}
}
}
return target;
}
}
}