This project is read-only.

SimpleInjector appropriate for our needs?

Apr 27, 2013 at 5:26 PM
I'm looking at DI frameworks for a migration of our middleware to more contemporary design practices. Our middleware is used by many different deliverables:
  • a legacy fat client Forms app
  • a variety of Windows Services
  • WCF-based services
  • an upcoming Web-based interface (it won't be in ASP though, just the middleware or services for data access and business logic)
One somewhat challenging thing I find about DI is the multi-threaded or service-based use, where you can have several different threads independently using the middleware, and you want each call context to often be getting many (but not necessarily all) of its instances independently. For example, I may want all contexts to share a threadsafe lookup caching service, but may want all the threads (or call contexts) to have separate objects when they do data manipulation.

I read the docs about SI Scopes, and that seems like something I want, but it is still not clear how scopes interact with threads. Any tips would be appreciated! Thanks, Brad
Apr 27, 2013 at 5:46 PM
The answer is simple: scope == thread.

The LifetimeScope lifestyle that Simple Injector provides is thread-dependent. Internally it used thread-local storage. It should be on a single thread and it contains some protection to prevent it from being used over multiple threads. You can nest scopes and the scopes will be oblivious of any scope that is defined on a different thread.
Apr 28, 2013 at 7:45 PM
Also take a look at the How To Work with dependency injection in multi-threaded applications section in the wiki documentation.
Marked as answer by dot_NET_Junkie on 11/5/2013 at 7:40 AM