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,37 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace TheXamlGuy.Framework.Core
{
public static class IHostBuilderExtensions
{
public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder, string contentRoot, bool createDirectory)
{
if (!Directory.Exists(contentRoot) && createDirectory)
{
Directory.CreateDirectory(contentRoot);
}
return hostBuilder.UseContentRoot(contentRoot);
}
public static IHostBuilder ConfigureEvents(this IHostBuilder hostBuilder, Action<IEventBuilder> builderDelegate)
{
hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
{
EventBuilder? builder = new();
builderDelegate?.Invoke(builder);
foreach (IEventBuilderConfiguration? configuration in builder.Configurations)
{
Type? type = configuration.GetType().GetGenericArguments()[0];
serviceCollection.AddSingleton(typeof(IEventBuilderConfiguration<>).MakeGenericType(type), configuration);
serviceCollection.AddSingleton(typeof(EventHandler<>).MakeGenericType(type));
}
});
return hostBuilder;
}
}
}