-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Func Factories cause a StackOverflow exception #24
Comments
I think it probably gets caught in this cycle:
I'll investigate when I get some time (slightly snowed under at the moment, sorry), and see if there's an easy fix. |
No problem, I can use Abstract Factories at the moment |
You could also do something like |
That's exactly what i want, and it worked. Although i think i only need to configure for the parent view model, either one of them is InSingletonScope should break the deadlock. Also because my child view model is the base of every business view model in our project, lots of view models...
It appears to be working, but i don't know whether my understanding is correct |
The The I hope that makes sense, rather than confusing things further... |
Yeah, I was right in my guess as to what's going on. When it tries to create that Func itself, it's trying to do something like It could instead do something like So, trade-offs. Giving better error messages vs stackoverflowing in some rare cases. I'm currently tempted to keep things as they are and document this case, but I'm still thinking about it. Open to feedback! |
that's a lot to take in, -.- Our project in short is like a I understand Hope you understand what i'm saying. I think the reason why I make On the other hand, why does not Abstract Factories cause a |
I think I follow. Like I said, making that Func binding singleton or transient really makes no difference. The difference is effectively this: // Singleton:
var parentFactory = () => new ParentViewModel(container.Get<ChildViewModel>());
var c1 = new ChildViewModel(parentFactory);
var c2 = new ChildViewModel(parentFactory);
// Transient:
var c1 = new ChildViewModel(() => new ParentViewModel(container.Get<ChildViewModel>()));
var c2 = new ChildViewModel(() => new ParentViewModel(container.Get<ChildViewModel>())); Abstract factories work because they're lazier: they call |
OK, Thank you very much for the explanation, I think I got it, have a great day |
Reopening, as I want to do something about this: either fix it, or document it. |
OK |
First of all, awesome project, thumb up, hope you continue this project.
I'm in a unique situation that I need a child view model to create a new parent view model; the parent view model is just a kind of content container, so it can create child view model dynamically according to the input model info. Constructors look like this:
When build it'll cause a StackOverflow. I've read "Circular Dependencies" wiki, but i still do not know how to configure a Func Factory.
Then I try to use Abstract Factories, it can avoid the stackoverflow exception, but I still wonder why Func Factory fails in this scenario.
Thank you in advance
The text was updated successfully, but these errors were encountered: