Grace: Cannot handle cyclic dependencies (StackOverflowExpeption)

Hello!

I just started writing Nancy.Bootstrapper wrapper over Grace IoC and collided with error. My lib: https://github.com/shmutalov/Unofficial.Nancy.Bootstrappers.Grace

All tests passed except one (if run them one by one), which causes a StackOverflowException:

Module that cannot be loaded: https://github.com/shmutalov/Unofficial.Nancy.Bootstrappers.Grace/blob/master/Unofficial.Nancy.Bootstrappers.Grace.Tests/Fakes/FakeNancyModuleWithRouteCacheProviderDependency.cs

NancyFx doc part about IRouteCacheProvider:

It’s not safe for a module to take a dependency on the cache (cyclic dependency)

Best regards, Sherzod

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (12 by maintainers)

Commits related to this issue

Most upvoted comments

OK so I took a look this weekend and the issue revolves around the fact that SingletonLifestyle eagerly creates singletons for performance purposes. I added a deferred singleton lifestyle option for this case.

All that said Nancy’s built in container is going to be much faster than child containers for Grace. It might be interesting to offer a second option that’s based on lifetime scopes instead of child scopes. The downside of lifetime scopes is you lose the ability to export types in the per request registration on the other hand it should be at least1000x faster than Grace using child scopes.

Currently Nancy’s built in container is very good at doing per request registration and I don’t think there is a way to make Grace anywhere near as fast at per request registration. On the other hand I think lifetime scopes would be an interesting option if you don’t need per request type registration as it should be much faster than Nancy.

Let me know if you are interested and I can put together an example of what I was thinking.

Hi @shmutalov

I’ll try and take a look at this over the weekend. I’ve had Nancy running with Grace in the past so I don’t envision this being a major change (fingers crossed).