common extensions and some utilities
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user