views:

215

answers:

1

Is there any reflection performance considerations when repeatedly calling container.Resolve<T>() when a resolution has already been established?

I'm using it in an MVC controller to resolve my data service, so it will be called on every HTTP request. I'm storing the container instance in Application state, and I'm using container controlled lifetime so it maintains a singleton instance of my resolved class. My assumption is that while the container is alive and has created a new instance of the service, it will not need to use reflection on subsequent calls to resolve it.

I'm considering keeping a reference to the resolved class instead if performance of Resolve<T>() is an issue. But with the singleton lifetime setup, it seems like I would be duplicating something that's already built-in.

+2  A: 

While not directly answering your question, Torkel Ödegaard's IoC container benchmarks suggest that you'll not be seeing a major performance hit related to resolving dependecies.

Ergwun
Thanks Ergwun. I totally forgot I posted this a few months back. Thanks for the link. That's very informative.
Nathan