diff --git a/Robust.Shared/GameObjects/EntitySystemManager.cs b/Robust.Shared/GameObjects/EntitySystemManager.cs index f6d3ddc54..a75842296 100644 --- a/Robust.Shared/GameObjects/EntitySystemManager.cs +++ b/Robust.Shared/GameObjects/EntitySystemManager.cs @@ -114,7 +114,7 @@ namespace Robust.Shared.GameObjects { Logger.DebugS("go.sys", "Initializing entity system {0}", type); // Force IoC inject of all systems - var instance = _typeFactory.CreateInstanceUnchecked(type); + var instance = _typeFactory.CreateInstanceUnchecked(type, oneOff: true); _systems.Add(type, instance); diff --git a/Robust.Shared/IoC/DynamicTypeFactory.cs b/Robust.Shared/IoC/DynamicTypeFactory.cs index 9636f4508..117a9cd67 100644 --- a/Robust.Shared/IoC/DynamicTypeFactory.cs +++ b/Robust.Shared/IoC/DynamicTypeFactory.cs @@ -45,8 +45,9 @@ namespace Robust.Shared.IoC /// The type MUST have a parameterless constructor. /// /// Type of object to instantiate. + /// If true, do not cache injector delegates. /// Newly created object. - object CreateInstanceUnchecked(Type type); + object CreateInstanceUnchecked(Type type, bool oneOff = false); /// /// Constructs a new instance of the given type with Dependencies resolved. @@ -101,12 +102,16 @@ namespace Robust.Shared.IoC /// /// The dynamic type factory to use. /// The type to instantiate. + /// If true, do not cache injector delegates. /// The type that the instance will be cast to. /// Newly created object, cast to . - internal static T CreateInstanceUnchecked(this IDynamicTypeFactoryInternal dynamicTypeFactory, Type type) + internal static T CreateInstanceUnchecked( + this IDynamicTypeFactoryInternal dynamicTypeFactory, + Type type, + bool oneOff = false) { DebugTools.Assert(typeof(T).IsAssignableFrom(type), "type must be subtype of T"); - return (T) dynamicTypeFactory.CreateInstanceUnchecked(type); + return (T) dynamicTypeFactory.CreateInstanceUnchecked(type, oneOff); } /// @@ -117,7 +122,10 @@ namespace Robust.Shared.IoC /// The arguments to pass to the constructor. /// The type that the instance will be cast to. /// Newly created object, cast to . - internal static T CreateInstanceUnchecked(this IDynamicTypeFactoryInternal dynamicTypeFactory, Type type, object[] args) + internal static T CreateInstanceUnchecked( + this IDynamicTypeFactoryInternal dynamicTypeFactory, + Type type, + object[] args) { DebugTools.Assert(typeof(T).IsAssignableFrom(type), "type must be subtype of T"); return (T) dynamicTypeFactory.CreateInstanceUnchecked(type, args); @@ -165,13 +173,13 @@ namespace Robust.Shared.IoC return CreateInstanceUnchecked(); } - public object CreateInstanceUnchecked(Type type) + public object CreateInstanceUnchecked(Type type, bool oneOff = false) { if (type == null) throw new ArgumentNullException(nameof(type)); var instance = Activator.CreateInstance(type)!; - _dependencies.InjectDependencies(instance); + _dependencies.InjectDependencies(instance, oneOff); return instance; }