z4kn4fein / stashbox

A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
https://z4kn4fein.github.io/stashbox
MIT License
140 stars 10 forks source link

DefinesScope() does not work correctly with dependencies #84

Closed schuettecarsten closed 4 years ago

schuettecarsten commented 4 years ago

I have the following classes/constructors:

public ProductCache(ProductRepository repo)

public ProductService(ProductRepository repo, ProductCache cache)

The ProductCache is registered using .DefinesScope().WithLifetime(Lifetimes.Singleton).WithoutDisposalTracking(). The ProductService is transient.

When I now request a ProductService instance from Stashbox, the ProductCache instance (cache) is created in a separate scope. That's fine so far. But the repo parameter value in the ProductCache constructor call and in the ProductRepository constructor call are the same. I would expect that different repo instances are created here, as the ProductCache should completely live in a separate scope.

z4kn4fein commented 4 years ago

I built up this scenario in this test but it's passing, could you check it please that I missed something or what could be the difference from what you described? Thanks!

schuettecarsten commented 4 years ago

Hmm, okay, it looks like it was an error on my side, sorry.