Skip to content
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

[bug] inconsistency when resolving service with dependency overrides #166

Open
kicsiede opened this issue Apr 26, 2024 · 0 comments
Open

Comments

@kicsiede
Copy link

When dealing with scoped instance resolution and dependency overrides, an inconsistency arises when attempting to resolve a service for the second time with different overrides. In the following example, I would expect both m2 and m3 to either throw an exception (the value of the dependency should be associated with the scope, and the override must match) or resolve to the first successful result. Perhaps a resolution option could be introduced to either ignore overrides if resolution is possible or throw on mismatch.

var c = new StashboxContainer();
c.RegisterScoped<Service>();

using (c.BeginScope())
{
    var m = c.Resolve<Service>(["d1"]);
    var m2 = c.Resolve<Service>(["d2"]); // returns instance with "d1"
    var m3 = c.Resolve<Service>();       // ResolutionFailedException
    var eq = m == m2;
}

public class Service
{
    [Stashbox.Attributes.Dependency] // dependency is passed as a dependency override
    public string Name;
}
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

1 participant