Start to port main gut of the foundation
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
public static class IServiceFactoryExtensions
|
||||
{
|
||||
public static T? Get<T>(this IServiceFactory serviceFactory)
|
||||
{
|
||||
return serviceFactory.Get<T>(typeof(T));
|
||||
}
|
||||
|
||||
public static T Create<T>(this IServiceFactory serviceFactory, params object?[] parameters)
|
||||
{
|
||||
return serviceFactory.Create<T>(typeof(T), parameters);
|
||||
}
|
||||
|
||||
public static object? Create(this IServiceFactory serviceFactory, Type type)
|
||||
{
|
||||
ServiceFactoryDescriptor? descriptor = new(serviceFactory);
|
||||
return descriptor.Create(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user