Reputation: 73
I was wondering is it safe to implement StructureMap IContainer as singleton and use it that way in MVC SPA application with WebApi? My idea was to share the same instance of IContainer object between IDependencyResolver(s) for MVC controllers and WebApi like:
For<IContainer>().Singleton();
Container needs to be configured only once at application start without the need to change configuration at runtime.
Upvotes: 2
Views: 688
Reputation: 172826
Yes, it is thread-safe. Creating a single container instance for the entire application is the advised thing to do. DI containers are optimized for this scenario and perform rather poorly when created on a per-request basis.
Upvotes: 2