Add project files.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using TheXamlGuy.Framework.Core;
|
||||
|
||||
namespace TheXamlGuy.Framework.Avalonia;
|
||||
|
||||
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<ITemplateDescriptorProvider, TemplateDescriptorProvider>()
|
||||
.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,17 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TheXamlGuy.Framework.Core;
|
||||
|
||||
namespace TheXamlGuy.Framework.Avalonia;
|
||||
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddRequiredAvalonia(this IServiceCollection serviceCollection)
|
||||
{
|
||||
return serviceCollection
|
||||
.AddSingleton<IRouter, Router>()
|
||||
.AddSingleton<IRouteDescriptorCollection, RouteDescriptorCollection>()
|
||||
.AddSingleton<IRouterContext, RouterContext>()
|
||||
.AddTransient<IMediatorHandler<Navigate>, NavigateHandler>()
|
||||
.RegisterHandlers();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user