You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But, when I changed the ChildLifetimeScope as follows
publicclassChildLifetimeScope:LifetimeScope{protectedoverridevoidConfigure(IContainerBuilderbuilder){builder.Register<A>(Lifetime.Singleton).AsSelf();// I changed this part.builder.RegisterBuildCallback(resolver =>{Debug.Log("ChildLifetimeScope "+string.Join(",",resolver.Resolve<IEnumerable<A>>()));});}}
logs changed to
BaseLifetimeScope A 0
ChildLifetimeScope A 1,A 2
.
I assumed It would be like ChildLifetimeScope A 1,A 0.
I don't know what the intended behavior is, but I don't think the result is intended.
The text was updated successfully, but these errors were encountered:
📝
Internally, the key of the ConcurrentDictionary holding the Singleton is Registration, but when multiple registrations are found in the parent and child, the keys don't match, so it looks like they are duplicate instantiated.
If a Singleton of the same type is registered for each Parent/Child, each container can have an instance. (This has been the specification for some time.)
In this case, when Child resolves IEnumerable, it searches for an instance of each Parent/Child. That is, the number of elements will be 2
If Singleton already exists in Parent, it is used.
First, I prepared these classes.
Log
This seems fine.
But, when I changed the ChildLifetimeScope as follows
logs changed to
.
I assumed It would be like
ChildLifetimeScope A 1,A 0
.I don't know what the intended behavior is, but I don't think the result is intended.
The text was updated successfully, but these errors were encountered: