-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Resolve caches object[] args values #29
Comments
@kirodge, Thanks for posting. Yes, it is probably a cache, but it should not be there because of arguments. I will check. |
Thanks, I created a PR for testing the issue |
The fix is available in DryIoc v3.1.0-preview-03 |
Thanks a lot for the quick fix @dadhi. |
@dadhi Set milestone 3.1.0? |
yep. |
I would set milestone myself, if I was able to. Any due date for 3.1? |
It will be a v4. Currently in a preview. Soonish I hope. |
This issue is a show stopper for my project as well. |
V4 will be here soon. If you are watching the repo, you see that I am closing the last bugs. Regarding back ports, I am open for PRs. |
EDIT: Actually, it appears to be another issue. Please see #105. It appears that the issue is still there in v4.0.1. I've prepared the tiniest use case I could come up with and placed it in a .NET fiddle. Here's the code, for completeness: // @nuget: DryIoc.dll -Version 4.0.1
using System;
using DryIoc;
public class Program
{
public static void Main()
{
using (var container = new Container(ConfigureContainer))
{
container.Register<IAlpha, Alpha>();
container.Register<IBravo, Bravo>();
using (var scope = container.OpenScope())
{
Console.WriteLine("--- Scope #1");
scope.ResolveNamed<IAlpha>("Alice");
scope.ResolveNamed<IBravo>("Bob");
}
using (var scope = container.OpenScope())
{
Console.WriteLine("--- Scope #2");
// I would expect the Container to throw on the following line,
// because it doesn't know how to create an instance of Alpha.
// Instead, it happily creates an Alpha named Bob!
scope.ResolveNamed<IBravo>("Bob");
}
}
}
static Rules ConfigureContainer(Rules rules)
{
return rules
.With(FactoryMethod.ConstructorWithResolvableArguments)
.WithDefaultReuse(Reuse.ScopedOrSingleton);
}
}
public static class ResolverExtensions
{
public static TService ResolveNamed<TService>(this IResolver @this, string name)
{
return @this.Resolve<TService>(args: new object[] { name });
}
}
public abstract class Service
{
protected Service(string name)
{
Console.WriteLine("This is an instance of {0} called {1}.", GetType().Name, name);
}
}
public interface IAlpha { }
public interface IBravo { }
public sealed class Alpha : Service, IAlpha
{
public Alpha(string name)
: base(name) { }
}
public sealed class Bravo : Service, IBravo
{
public Bravo(string name, IAlpha alpha)
: base(name) { }
} |
Hi,
I'm not sure if this is a issue or by design.
I am trying to create a ViewModel-factory
On the first call to CreateViewModel with a System.Guid as parameter
var editViewModel = _viewModelFactory.CreateViewModel<IEditViewModel>(guidId);
everything works as expected. The constructor of the registered EditViewModel is run with the provided guidId, and other parameters injected. However on a second call
var editViewModel = _viewModelFactory.CreateViewModel<IEditViewModel>(anotherGuidId);
the guid-value from the first call is injected to the constructor again.
It seems to me that DryIoc's Resolve caches object[] args values.
Is this intended?
I'm aware that I can use
but not all of my viewmodels require a guid as parameter. Some require no guid, some require two, and some might require other values only known at runtime.
Thanks for any advice
The text was updated successfully, but these errors were encountered: