Closed HugoLemieux closed 1 year ago
Hi, thanks for the tests. I will check what's happening here.
@HugoLemieux
In order to fix the thing, you need to add the setup: Setup.With(asResolutionCall: true)
to the dependency as following:
public void Resolve_WithResolveInAnotherScopeBefore_Fail()
{
var container = new Container();
container.Register<ScopedType>(Reuse.Scoped);
container.Register<IScopedTypeDependency, DefaultScopedTypeDependency>(
Reuse.Scoped,
setup: Setup.With(asResolutionCall: true)); // fixes the thing
ScopedType scopedTypeObj;
using (var scope1 = container.OpenScope())
scope1.Resolve<ScopedType>();
var dependency = new AnotherScopedTypeDependency();
using (var scope2 = container.OpenScope())
{
scope2.Use<IScopedTypeDependency>(dependency);
scopedTypeObj = scope2.Resolve<ScopedType>();
}
Assert.AreSame(scopedTypeObj.Dependency, dependency);
}
The reason is explained here: https://github.com/dadhi/DryIoc/blob/master/docs/DryIoc.Docs/RulesAndDefaultConventions.md#injecting-dependency-asresolutioncall
Hi, If I try to replace a scoped dependency of a scoped type inside a scope after having resolved the same scoped type in another scope before, it returns the same dependency of the type returned in the previous scope.
It is not doing this if I do not resolve the scoped type in another scope before.
Here's a test class reproducing both cases: `using DryIoc;
namespace DryIocScopedType {
}`
How can I replace scoped dependencies when their scoped dependent types could have been resolved in others scopes before?
Regards,