Problems with registration and injection of an orchestrator with scene lifetimeScope implementing the IStartable interface. #748
Replies: 1 comment
-
|
You’re injecting a Scene EntryPoint (IStartable) into services of the same scope. EntryPoints are created/resolved lazily by VContainer during Run and wrapping them in Lazy<> internally. Resolving one from inside the same scope while it’s being created causes the re-entrant Lazy error: “ValueFactory attempted to access the Value property…”. Now:
Alternative options (if you must keep IStartable on the orchestrator)
Why this works: EntryPoints are roots (created by the container and invoked by VContainer’s player loop). They should depend on services, not be depended on. Splitting “startup trigger” (EntryPoint) from “orchestrator API” (service) breaks the circular path and removes the re-entrant Lazy access. I reccomend you read this also: VContainer docs — EntryPoint pattern: https://vcontainer.hadashikick.jp/integrations/entrypoint |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Good afternoon,
I have a global LifetimeScope in this registry with the following line a global orchestrator.
builder.RegisterEntryPoint(Lifetime.Singleton).As().WithParameter("initializationServiceOrder", GlobalServicesInitializationList.SceneInitializationOrder);
This orchestrator I inject it and it works perfectly. Class definition:
public class GlobalOrchestrator : IStartable, IGlobalOrchestrator
Further on, I have a scene lifetimeScope and I register a scene orchestrator as follows:
builder.RegisterEntryPoint().As().WithParameter("initializationPluginOrder", PluginInitializationList.SceneInitializationOrder);
Both the global orchestrator and the scene orchestrator implement the IStartable interface.
When trying to inject it into a scene service of the same LifetimeScope the following error occurs:
InvalidOperationException: ValueFactory attempted to access the Value property of this instance. System.Lazy1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) (at :0)
System.Lazy1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) (at :0) System.Lazy1[T].CreateValue () (at :0)
System.Lazy1[T].get_Value () (at :0) VContainer.ScopedContainer.CreateTrackedInstance (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:178) VContainer.ScopedContainer.ResolveCore (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:163) VContainer.ScopedContainer.Resolve (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:115) VContainer.ScopedContainer.Resolve (System.Type type) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:91) VContainer.IObjectResolverExtensions.ResolveOrParameter (VContainer.IObjectResolver resolver, System.Type parameterType, System.String parameterName, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/IObjectResolverExtensions.cs:59)
VContainer.Internal.ReflectionInjector.InjectFields (System.Object obj, VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:66) VContainer.Internal.ReflectionInjector.Inject (System.Object instance, VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:26)
VContainer.Unity.PrefabComponentProvider.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Unity/InstanceProviders/PrefabComponentProvider.cs:46)
VContainer.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Registration.cs:33)
VContainer.ScopedContainer+<>c__DisplayClass17_0.<.ctor>b__1 () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:82)
System.Lazy1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) (at :0) System.Lazy1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) (at :0)
System.Lazy1[T].CreateValue () (at :0) System.Lazy1[T].get_Value () (at :0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:178)
VContainer.ScopedContainer.ResolveCore (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:163)
VContainer.ScopedContainer.Resolve (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:115)
VContainer.Internal.CollectionInstanceProvider.SpawnInstance (VContainer.IObjectResolver currentScope, System.Collections.Generic.IReadOnlyList1[T] entirelyRegistrations) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs:96) VContainer.Internal.CollectionInstanceProvider.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs:75) VContainer.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Registration.cs:33) VContainer.ScopedContainer.ResolveCore (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:169) VContainer.ScopedContainer.Resolve (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:115) VContainer.ScopedContainer.Resolve (System.Type type) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:91) VContainer.IObjectResolverExtensions.ResolveOrParameter (VContainer.IObjectResolver resolver, System.Type parameterType, System.String parameterName, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/IObjectResolverExtensions.cs:59)
VContainer.Internal.ReflectionInjector.InjectMethods (System.Object obj, VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:97) VContainer.Internal.ReflectionInjector.Inject (System.Object instance, VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:28)
VContainer.Internal.ReflectionInjector.CreateInstance (VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:46) VContainer.Internal.InstanceProvider.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/InstanceProvider.cs:21) VContainer.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Registration.cs:33) VContainer.ScopedContainer+<>c__DisplayClass17_0.<.ctor>b__1 () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:82) System.Lazy1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) (at :0)
System.Lazy1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) (at :0) System.Lazy1[T].CreateValue () (at :0)
System.Lazy1[T].get_Value () (at :0) VContainer.ScopedContainer.CreateTrackedInstance (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:178) VContainer.ScopedContainer.ResolveCore (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:163) VContainer.ScopedContainer.Resolve (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:115) VContainer.Internal.CollectionInstanceProvider.SpawnInstance (VContainer.IObjectResolver currentScope, System.Collections.Generic.IReadOnlyList1[T] entirelyRegistrations) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs:96)
VContainer.Internal.CollectionInstanceProvider.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs:75)
VContainer.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Registration.cs:33)
VContainer.ScopedContainer.ResolveCore (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:169)
VContainer.ScopedContainer.Resolve (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:115)
VContainer.ScopedContainer.Resolve (System.Type type) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:91)
VContainer.IObjectResolverExtensions.ResolveOrParameter (VContainer.IObjectResolver resolver, System.Type parameterType, System.String parameterName, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/IObjectResolverExtensions.cs:59) VContainer.Internal.ReflectionInjector.InjectMethods (System.Object obj, VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:97)
VContainer.Internal.ReflectionInjector.Inject (System.Object instance, VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:28) VContainer.Internal.ReflectionInjector.CreateInstance (VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList1[T] parameters) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/ReflectionInjector.cs:46)
VContainer.Internal.InstanceProvider.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/InstanceProvider.cs:21)
VContainer.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Registration.cs:33)
VContainer.ScopedContainer+<>c__DisplayClass17_0.<.ctor>b__1 () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:82)
System.Lazy1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) (at :0) System.Lazy1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) (at :0)
System.Lazy1[T].CreateValue () (at :0) System.Lazy1[T].get_Value () (at :0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:178)
VContainer.ScopedContainer.ResolveCore (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:163)
VContainer.ScopedContainer.Resolve (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:115)
VContainer.Internal.CollectionInstanceProvider.SpawnInstance (VContainer.IObjectResolver currentScope, System.Collections.Generic.IReadOnlyList1[T] entirelyRegistrations) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs:96) VContainer.Internal.ContainerLocalInstanceProvider.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Internal/InstanceProviders/ContainerLocalInstanceProvider.cs:26) VContainer.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Registration.cs:33) VContainer.ScopedContainer+<>c__DisplayClass17_0.<.ctor>b__1 () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:82) System.Lazy1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) (at :0)
System.Lazy1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) (at :0) System.Lazy1[T].CreateValue () (at :0)
System.Lazy1[T].get_Value () (at :0) VContainer.ScopedContainer.CreateTrackedInstance (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:178) VContainer.ScopedContainer.ResolveCore (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:166) VContainer.ScopedContainer.Resolve (VContainer.Registration registration) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:115) VContainer.ScopedContainer.Resolve (System.Type type) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:91) VContainer.IObjectResolverExtensions.Resolve[T] (VContainer.IObjectResolver resolver) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/IObjectResolverExtensions.cs:10) VContainer.Unity.EntryPointDispatcher.Dispatch () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Unity/EntryPointDispatcher.cs:59) VContainer.Unity.EntryPointsBuilder+<>c.b__0_0 (VContainer.IObjectResolver container) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Unity/ContainerBuilderUnityExtensions.cs:19) VContainer.ContainerBuilder.EmitCallbacks (VContainer.IObjectResolver container) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/ContainerBuilder.cs:175) VContainer.ScopedContainerBuilder.BuildScope () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/ContainerBuilder.cs:41) VContainer.ScopedContainer.CreateScope (System.Action1[T] installation) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:126)
VContainer.Container.CreateScope (System.Action1[T] installation) (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Container.cs:263) VContainer.Unity.LifetimeScope.Build () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Unity/LifetimeScope.cs:200) VContainer.Unity.LifetimeScope.Awake () (at ./Library/PackageCache/jp.hadashikick.vcontainer@331f0bbb68/Runtime/Unity/LifetimeScope.cs:146)
Any idea why when I inject the orchestrator I get this error with respect to the registration?
Beta Was this translation helpful? Give feedback.
All reactions