Skip to content

ResolverOverride.OnType throws while resolving HierarchicalLifetimeManager scoped objects #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthewz0584 opened this issue May 30, 2018 · 0 comments
Milestone

Comments

@matthewz0584
Copy link

Unity.Container 5.8.6
.Net Framewrok 4

public class Foo : IFoo
{
     public Foo(string view) {}
}

[Test]
public void ParameterOverridesWithOnType()
{
     var ioc = new UnityContainer();
     ioc.RegisterType<IFoo, Foo>(new HierarchicalLifetimeManager());
            
     ioc.CreateChildContainer().Resolve<IFoo>(new ParameterOverride("view", "qq").OnType<Foo>());
     ioc.CreateChildContainer().Resolve<IFoo>(new ParameterOverride("view", "qq").OnType<Foo>());
}

The test above fails at the second call to Resolve with exception:
"Unity.Exceptions.ResolutionFailedException : Resolution of the dependency failed, type = 'Tests.UnityTests+IFoo', name = '(none)'.
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type String cannot be constructed. You must configure the container to supply this value."

Single call to Resolve works as expected. HierarchicalLifetimeManager and CreateChildContainer are necessary preconditions for the error. The test worked allright with the older Microsoft.Practices v2.1 unity container.

@ENikS ENikS added the bug label Aug 6, 2018
@ENikS ENikS added this to the 5.8.7 milestone Aug 6, 2018
ENikS added a commit that referenced this issue Aug 6, 2018
@ENikS ENikS closed this as completed in dd7e617 Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants