/// <summary> /// Returns the injector instance for specified type. /// </summary> public static TypeInjector GetInjector(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } // Cached? if (Handlers.TryGetValue(type, out TypeInjector value)) { return(value); } // Get base type's injector TypeInjector baseInjector = null; Type baseType = type.BaseType; if (baseType != null && baseType != typeof(object)) { baseInjector = GetInjector(baseType); } // Create new and cache value = new TypeInjector(type, baseInjector); value.Initialize(); Handlers.Add(type, value); return(value); }
/// <summary> /// Performs injection on specified class-type object. /// </summary> public static void Inject(object obj, IDependencyContainer container) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (container == null) { throw new ArgumentNullException(nameof(container)); } TypeInjector injector = GetInjector(obj.GetType()); injector.Inject(obj, container); }
public TypeInjector(Type type, TypeInjector baseInjector) { this.type = type; this.baseInjector = baseInjector; }