Iam using structure map for resolving my dependencies, however i have a rather special case where i want a dependency to be constructed through a method call.
This method shoudl be called everytime i cann GetInstance() however it only executes once.
My declaration looks like this:
x.For<UserService>().Use(c => { return MultiObjectProvider.GetInstance<UserService>(); });
is also tried
x.For<UserService>().LifecycleIs(new ThreadLocalStorageLifecycle()).Use(c => { return MultiObjectProvider.GetInstance<UserService>(); });
which didnt change anything.
Does anyone know how i can make structuremap resolve every time ?
That should work. I think the problem may be in your
MultiObjectProvider.GetInstancemethod (which perhaps returns the same instance in successive calls) rather than here.Here’s a quick Unit Test I put together to mimic what you have (I just used System.Guid instead of your UserService), and which passes.
Side note: You can simplify your syntax as follows:
And even