Start to port main gut of the foundation

This commit is contained in:
Daniel Clark
2022-12-05 17:47:16 +00:00
parent 82a83456f4
commit 3b09265a30
44 changed files with 1075 additions and 1 deletions
@@ -0,0 +1,26 @@
namespace Toolkit.Foundation
{
public class ServiceFactory : IServiceFactory
{
private readonly Func<Type, object?> factory;
private readonly Func<Type, object?[], object> creator;
public ServiceFactory(Func<Type, object?> factory, Func<Type, object?[], object> creator)
{
this.factory = factory;
this.creator = creator;
}
public T? Get<T>(Type type)
{
T? value = (T?)factory(type);
return value;
}
public T Create<T>(Type type, params object?[] parameters)
{
dynamic? lookup = factory(typeof(IServiceCreator<>).MakeGenericType(type));
return lookup is not null ? (T)lookup.Create(creator, parameters) : (T)creator(type, parameters);
}
}
}