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
After using IResolverContext.UseInstance the first time, the next UseInstance with same interface-based serviceType (and even implementation type) will not replace previous instance.
(even with or without IfAlreadyRegistered.Replace)
Example:
interfaceIUser{stringUniqueId{get;set;}}classUser:IUser,IEquatable<User>{publicGuidId{get;set;}stringUniqueId{get;set;}// ...// IEquatable.Equals(User) and overriden object.Equals are provided}[Fact]publicvoidTest(){// base ctor creates Scope = Container.OpenScope()varorigUser=Scope.Resolve<IUser>();// this is from normal registrationvarnewUser=newUser{Id=Guid.NewGuid()};Scope.UseInstance(newUser,IfAlreadyRegistered.Replace);// this is FINE, this instance is usedScope.UseInstance(origUser,IfAlreadyRegistered.Replace);// this is NOT happening// ... nor any subsequent calls UseInstance}
not really for me Solution
ℹ️ Using direct class type User will make it work properly.
This is not an option for me due to abstraction, I need to use the interface type.
Any help is appreciated if I can work around this problem.
(tried to override GetHashCode() as Container.UseInstance is based on that, but it is used on ServiceType which is the interface and RuntimeHelpers.GetHashCode(typeof(IUser)) does not change during type, shouldn't be a problem)
The text was updated successfully, but these errors were encountered:
Btw I've tried Use() as well looking at the container code as it is (will be) marked as obsolete, but didn't work even for first time. I hope this cache invalidation will make it happen.
After using
IResolverContext.UseInstance
the first time, the next UseInstance with same interface-based serviceType (and even implementation type) will not replace previous instance.(even with or without IfAlreadyRegistered.Replace)
Example:
not really for meSolutionℹ️ Using direct class type
User
will make it work properly.This is not an option for me due to abstraction, I need to use the interface type.
Any help is appreciated if I can work around this problem.
(tried to override GetHashCode() as Container.UseInstance is based on that, but it is used on ServiceType which is the interface and
RuntimeHelpers.GetHashCode(typeof(IUser))
does not change during type, shouldn't be a problem)The text was updated successfully, but these errors were encountered: