diff --git a/Robust.Client/ResourceManagement/ResourceCache.cs b/Robust.Client/ResourceManagement/ResourceCache.cs index b6ec40f24..cdcea4fcc 100644 --- a/Robust.Client/ResourceManagement/ResourceCache.cs +++ b/Robust.Client/ResourceManagement/ResourceCache.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using Robust.Client.Audio; using Robust.Shared.ContentPack; using Robust.Shared.IoC; +using Robust.Shared.Log; using Robust.Shared.Utility; namespace Robust.Client.ResourceManagement; @@ -16,7 +17,6 @@ namespace Robust.Client.ResourceManagement; /// internal sealed partial class ResourceCache : ResourceManager, IResourceCacheInternal, IDisposable { - [Shared.IoC.Dependency] private readonly IDependencyCollection _deps = default!; private readonly Dictionary _cachedResources = new(); private readonly Dictionary _fallbacks = new(); @@ -36,7 +36,8 @@ internal sealed partial class ResourceCache : ResourceManager, IResourceCacheInt var resource = new T(); try { - resource.Load(_deps, path); + var dependencies = IoCManager.Instance!; + resource.Load(dependencies, path); cache.Resources[path] = resource; return resource; } @@ -80,7 +81,8 @@ internal sealed partial class ResourceCache : ResourceManager, IResourceCacheInt var _resource = new T(); try { - _resource.Load(_deps, path); + var dependencies = IoCManager.Instance!; + _resource.Load(dependencies, path); resource = _resource; cache.Resources[path] = resource; return true; @@ -121,7 +123,8 @@ internal sealed partial class ResourceCache : ResourceManager, IResourceCacheInt try { - res.Reload(_deps, path); + var dependencies = IoCManager.Instance!; + res.Reload(dependencies, path); } catch (Exception e) { diff --git a/Robust.Shared/IoC/IoCManager.cs b/Robust.Shared/IoC/IoCManager.cs index 7c9ab2650..1eca24a00 100644 --- a/Robust.Shared/IoC/IoCManager.cs +++ b/Robust.Shared/IoC/IoCManager.cs @@ -50,7 +50,6 @@ namespace Robust.Shared.IoC /// /// This property will be null if has not been called on this thread yet. /// - [Obsolete("Resolve the IDependencyCollection directly without static methods (e.g., with a [Dependency] IDependencyCollection field)")] public static IDependencyCollection? Instance => _container.IsValueCreated ? _container.Value : null; /// @@ -103,7 +102,6 @@ namespace Robust.Shared.IoC /// Thrown if is false and has been registered before, /// or if an already instantiated interface (by ) is attempting to be overwritten. /// - [Obsolete("Use an IDependencyCollection instance instead of static methods")] public static void Register(bool overwrite = false) where TImplementation : class, TInterface where TInterface : class @@ -125,7 +123,6 @@ namespace Robust.Shared.IoC /// Thrown if is false and has been registered before, /// or if an already instantiated interface (by ) is attempting to be overwritten. /// - [Obsolete("Use an IDependencyCollection instance instead of static methods")] public static void Register<[MeansImplicitUse] T>(bool overwrite = false) where T : class { Register(overwrite); @@ -146,7 +143,6 @@ namespace Robust.Shared.IoC /// Thrown if is false and has been registered before, /// or if an already instantiated interface (by ) is attempting to be overwritten. /// - [Obsolete("Use an IDependencyCollection instance instead of static methods")] public static void Register(DependencyFactoryDelegate factory, bool overwrite = false) where TImplementation : class, TInterface where TInterface : class @@ -169,7 +165,6 @@ namespace Robust.Shared.IoC /// If true, do not throw an if an interface is already registered, /// replace the current implementation instead. /// - [Obsolete("Use an IDependencyCollection instance instead of static methods")] public static void RegisterInstance(object implementation, bool overwrite = false) where TInterface : class { @@ -198,7 +193,6 @@ namespace Robust.Shared.IoC /// because the object graph still needs to be constructed for it. /// [System.Diagnostics.Contracts.Pure] - [Obsolete("Use dependency injection or an IDependencyCollection instance instead of static methods")] public static T Resolve() { DebugTools.Assert(_container.IsValueCreated, NoContextAssert); @@ -208,7 +202,6 @@ namespace Robust.Shared.IoC /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - [Obsolete("Use dependency injection or an IDependencyCollection instance instead of static methods")] public static void Resolve([NotNull] ref T? instance) { // Do not call into IDependencyCollection immediately for this, @@ -221,7 +214,6 @@ namespace Robust.Shared.IoC /// Resolve two dependencies manually. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - [Obsolete("Use dependency injection or an IDependencyCollection instance instead of static methods")] public static void Resolve([NotNull] ref T1? instance1, [NotNull] ref T2? instance2) { DebugTools.Assert(_container.IsValueCreated, NoContextAssert); @@ -234,7 +226,6 @@ namespace Robust.Shared.IoC /// Resolve three dependencies manually. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - [Obsolete("Use dependency injection or an IDependencyCollection instance instead of static methods")] public static void Resolve([NotNull] ref T1? instance1, [NotNull] ref T2? instance2, [NotNull] ref T3? instance3) { DebugTools.Assert(_container.IsValueCreated, NoContextAssert); @@ -247,7 +238,6 @@ namespace Robust.Shared.IoC /// Resolve four dependencies manually. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - [Obsolete("Use dependency injection or an IDependencyCollection instance instead of static methods")] public static void Resolve([NotNull] ref T1? instance1, [NotNull] ref T2? instance2, [NotNull] ref T3? instance3, [NotNull] ref T4? instance4) { DebugTools.Assert(_container.IsValueCreated, NoContextAssert); @@ -264,7 +254,6 @@ namespace Robust.Shared.IoC /// because the object graph still needs to be constructed for it. /// [System.Diagnostics.Contracts.Pure] - [Obsolete("Use dependency injection or an IDependencyCollection instance instead of static methods")] public static object ResolveType(Type type) { DebugTools.Assert(_container.IsValueCreated, NoContextAssert); @@ -295,7 +284,6 @@ namespace Robust.Shared.IoC /// Thrown if a dependency field on the object is not registered. /// /// - [Obsolete("Use an IDependencyCollection instance instead of static methods")] public static T InjectDependencies(T obj) where T : notnull { DebugTools.Assert(_container.IsValueCreated, NoContextAssert); diff --git a/Robust.Shared/Toolshed/Commands/Misc/IoCCommand.cs b/Robust.Shared/Toolshed/Commands/Misc/IoCCommand.cs index eb90a8d38..516dd9d9f 100644 --- a/Robust.Shared/Toolshed/Commands/Misc/IoCCommand.cs +++ b/Robust.Shared/Toolshed/Commands/Misc/IoCCommand.cs @@ -7,10 +7,9 @@ namespace Robust.Shared.Toolshed.Commands.Misc; [ToolshedCommand] internal sealed class IoCCommand : ToolshedCommand { - [Dependency] private readonly IDependencyCollection _deps = default!; [CommandImplementation("registered")] - public IEnumerable Registered() => _deps.GetRegisteredTypes(); + public IEnumerable Registered() => IoCManager.Instance!.GetRegisteredTypes(); [CommandImplementation("get")] - public object? Get([PipedArgument] Type t) => _deps.ResolveType(t); + public object? Get([PipedArgument] Type t) => IoCManager.ResolveType(t); } diff --git a/Robust.Shared/ViewVariables/ViewVariablesManager.Domains.cs b/Robust.Shared/ViewVariables/ViewVariablesManager.Domains.cs index 07bc2e805..d244d9e3e 100644 --- a/Robust.Shared/ViewVariables/ViewVariablesManager.Domains.cs +++ b/Robust.Shared/ViewVariables/ViewVariablesManager.Domains.cs @@ -43,9 +43,9 @@ internal abstract partial class ViewVariablesManager private (ViewVariablesPath? Path, string[] Segments) ResolveIoCObject(string path) { - var empty = (new ViewVariablesInstancePath(_deps), Array.Empty()); + var empty = (new ViewVariablesInstancePath(IoCManager.Instance), Array.Empty()); - if (string.IsNullOrEmpty(path)) + if (string.IsNullOrEmpty(path) || IoCManager.Instance == null) return empty; var segments = path.Split('/'); @@ -58,24 +58,24 @@ internal abstract partial class ViewVariablesManager if (!_reflectionMan.TryLooseGetType(service, out var type)) return EmptyResolve; - return _deps.TryResolveType(type, out var obj) + return IoCManager.Instance.TryResolveType(type, out var obj) ? (new ViewVariablesInstancePath(obj), segments[1..]) : EmptyResolve; } private IEnumerable? ListIoCPaths(string[] segments) { - if (segments.Length > 1) + if (segments.Length > 1 || IoCManager.Instance is not {} deps) return null; if (segments.Length == 1 && _reflectionMan.TryLooseGetType(segments[0], out var type) - && _deps.TryResolveType(type, out _)) + && deps.TryResolveType(type, out _)) { return null; } - return _deps.GetRegisteredTypes() + return deps.GetRegisteredTypes() .Select(t => t.Name); } @@ -161,7 +161,7 @@ internal abstract partial class ViewVariablesManager { var empty = (new ViewVariablesInstancePath(_protoMan), Array.Empty()); - if (string.IsNullOrEmpty(path)) + if (string.IsNullOrEmpty(path) || IoCManager.Instance == null) return empty; var segments = path.Split('/'); diff --git a/Robust.Shared/ViewVariables/ViewVariablesManager.cs b/Robust.Shared/ViewVariables/ViewVariablesManager.cs index 5ddf7e318..df1aa1574 100644 --- a/Robust.Shared/ViewVariables/ViewVariablesManager.cs +++ b/Robust.Shared/ViewVariables/ViewVariablesManager.cs @@ -22,7 +22,6 @@ internal abstract partial class ViewVariablesManager : IViewVariablesManager, IP [Dependency] private readonly IReflectionManager _reflectionMan = default!; [Dependency] private readonly INetManager _netMan = default!; [Dependency] private readonly ILogManager _logMan = default!; - [Dependency] private readonly IDependencyCollection _deps = default!; private readonly Dictionary> _cachedTraits = new(); diff --git a/Robust.UnitTesting/Shared/IoC/IoCManager_Test.cs b/Robust.UnitTesting/Shared/IoC/IoCManager_Test.cs index 792ade235..f56cce14a 100644 --- a/Robust.UnitTesting/Shared/IoC/IoCManager_Test.cs +++ b/Robust.UnitTesting/Shared/IoC/IoCManager_Test.cs @@ -4,7 +4,6 @@ using NUnit.Framework; using Robust.Shared.Analyzers; using Robust.Shared.IoC; using Robust.Shared.IoC.Exceptions; -#pragma warning disable CS0618 // Type or member is obsolete namespace Robust.UnitTesting.Shared.IoC { diff --git a/Robust.UnitTesting/Shared/Localization/LoadLocalizationTest.cs b/Robust.UnitTesting/Shared/Localization/LoadLocalizationTest.cs index af9952a10..a2fe3ee03 100644 --- a/Robust.UnitTesting/Shared/Localization/LoadLocalizationTest.cs +++ b/Robust.UnitTesting/Shared/Localization/LoadLocalizationTest.cs @@ -6,7 +6,6 @@ using Robust.Shared.ContentPack; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; -#pragma warning disable CS0618 // Type or member is obsolete namespace Robust.UnitTesting.Shared.Localization; diff --git a/Robust.UnitTesting/Shared/Reflection/ReflectionManager_Test.cs b/Robust.UnitTesting/Shared/Reflection/ReflectionManager_Test.cs index 6d256803b..1dca766f3 100644 --- a/Robust.UnitTesting/Shared/Reflection/ReflectionManager_Test.cs +++ b/Robust.UnitTesting/Shared/Reflection/ReflectionManager_Test.cs @@ -3,7 +3,6 @@ using Robust.Shared.IoC; using Robust.Shared.Reflection; using System.Collections.Generic; using JetBrains.Annotations; -#pragma warning disable CS0618 // Type or member is obsolete namespace Robust.UnitTesting.Shared.Reflection {