diff --git a/VContainer/Assets/Tests/ContainerTest.cs b/VContainer/Assets/Tests/ContainerTest.cs index a9320011..635d6618 100644 --- a/VContainer/Assets/Tests/ContainerTest.cs +++ b/VContainer/Assets/Tests/ContainerTest.cs @@ -671,7 +671,6 @@ public void TryResolveScoped() container.Dispose(); Assert.That(obj1.Disposed, Is.True); ->>>>>>> 1d6258b (Added Unit tests):VContainer/Assets/VContainer/Tests/ContainerTest.cs } } } diff --git a/VContainer/Assets/VContainer/Runtime/Container.cs b/VContainer/Assets/VContainer/Runtime/Container.cs index 648668ce..e7d0b925 100644 --- a/VContainer/Assets/VContainer/Runtime/Container.cs +++ b/VContainer/Assets/VContainer/Runtime/Container.cs @@ -18,7 +18,7 @@ public interface IObjectResolver : IDisposable /// This version of resolve looks for all of scopes /// object Resolve(Type type); - + /// /// Try resolve from type /// @@ -35,7 +35,9 @@ public interface IObjectResolver : IDisposable /// This version of resolve will look for instances from only the registration information already founds. /// object Resolve(Registration registration); + IScopedObjectResolver CreateScope(Action installation = null); + void Inject(object instance); bool TryGetRegistration(Type type, out Registration registration); } @@ -82,7 +84,14 @@ internal ScopedContainer( } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public object Resolve(Type type) => Resolve(FindRegistration(type)); + public object Resolve(Type type) + { + if (TryFindRegistration(type, out var registration)) + { + return Resolve(registration); + } + throw new VContainerException(type, $"No such registration of type: {type}"); + } public bool TryResolve(Type type, out object resolved) { @@ -174,15 +183,6 @@ object CreateTrackedInstance(Registration registration) return instance; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal Registration FindRegistration(Type type) - { - if (TryFindRegistration(type, out var registration)) - return registration; - - throw new VContainerException(type, $"No such registration of type: {type}"); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] internal bool TryFindRegistration(Type type, out Registration registration) { @@ -228,7 +228,7 @@ internal Container(Registry registry, object applicationOrigin = null) [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { - if (registry.TryGet(type, out var registration)) + if (TryGetRegistration(type, out var registration)) { return Resolve(registration); } @@ -238,12 +238,12 @@ public object Resolve(Type type) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryResolve(Type type, out object resolved) { - if (registry.TryGet(type, out var registration)) + if (TryGetRegistration(type, out var registration)) { resolved = Resolve(registration); return true; } - + resolved = default; return false; }