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

Encountering StackOverflowException/Crash with Decorate<T> #117

Closed
Mike-E-angelo opened this issue Mar 28, 2020 · 4 comments
Closed

Encountering StackOverflowException/Crash with Decorate<T> #117

Mike-E-angelo opened this issue Mar 28, 2020 · 4 comments
Milestone

Comments

@Mike-E-angelo
Copy link

Mike-E-angelo commented Mar 28, 2020

Greetings!

First off, really nice work with this library. It has worked very well for my purposes without issue.

Until now. 😁 It could be due to user error, however, so I wanted to check in and verify.

The issue I encountered was with using the Decorate method on my EntityFrameworkCore configuration. I have managed to reduce this to the following solution:

https://github.com/Mike-E-wins/Scrutor.EntityFramework

In particular, the code to reproduce is here:

https://github.com/Mike-E-wins/Scrutor.EntityFramework/blob/master/Scrutor.EntityFramework/UnitTest1.cs#L9-L17

Note that I was able to remove all EntityFramework code and use a simple singleton registration to reproduce this issue (the actual code where I encountered this is scoped).

When executed, the code either results in a never-ending loop, a StackOverflowException, or a crashed process.

For further context, I was attempting to create an initialized database due this issue here. So, I was attempting to do something along the line of the following when I encountered this issue:

.Decorate<ApplicationStorage>(x => {
	x.Database.EnsureCreated();
	return x;
})

My current workaround is to do the above with LightInject's Decorate method, but I would rather stick to IServiceCollection extension methods if possible, if that makes sense.

Thank you for any assistance/consideration towards this matter.

@khellang
Copy link
Owner

Hmm, I wonder if this could be because the service is registered as self?

@Mike-E-angelo
Copy link
Author

It could be, @khellang. It's not returning a new instance of a different type/reference, so that might be confusing things here.

Mariachi1231 pushed a commit to Mariachi1231/Scrutor that referenced this issue Sep 13, 2021
khellang pushed a commit that referenced this issue Jan 28, 2022
@khellang
Copy link
Owner

Close by #155

@Mike-E-angelo
Copy link
Author

Woohoo! Thank you so much for your efforts @khellang, @Mariachi1231, and team. 🙏

@khellang khellang added this to the v4.0.0 milestone Jan 28, 2022
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