common extensions and some utilities

This commit is contained in:
2025-03-19 00:18:40 +01:00
parent f80fd22a00
commit e62bd2aa6d
35 changed files with 323 additions and 58 deletions

View File

@@ -17,10 +17,10 @@ namespace RebootKit.Engine.Foundation {
}
private static readonly Logger Logger = new(nameof(DIContext));
private readonly Dictionary<Type, object> _bindingsMaps = new();
private readonly List<IFieldInjector> _fieldInjectors = new();
public DIContext() {
Bind(this);
@@ -54,6 +54,14 @@ namespace RebootKit.Engine.Foundation {
return (T) Resolve(typeof(T));
}
// @brief creates new instance of an object and injects dependencies
public T Create<T>() {
T instance = Activator.CreateInstance<T>();
Inject(instance);
return instance;
}
public void Inject<T>(T target) {
Type type = typeof(T);
@@ -99,7 +107,7 @@ namespace RebootKit.Engine.Foundation {
if (!Attribute.IsDefined(field, typeof(InjectAttribute))) {
return false;
}
object instance = context.Resolve(field.FieldType);
if (instance == null) {