This project is read-only.

Extend diagnostic service to cover common technology misconfigurations

Mar 27, 2014 at 9:14 AM
What are your thoughts on extending the container diagnostic services to scan for common technology misconfigurations?

For example a long time ago I created a WebApi DelegateHandler that is registered in the container as Transient and amongst other things has a reference to a DbContext (which luckily reads static data).

A DelegateHandler should be registered and composed as a Singleton and I believe that the container diagnostic service would be the perfect place to identify these sorts of misconfigurations.

There are similar examples of wrong lifestyles scattered throughout the internet.

Does anyone have any suggestions for other common frameworks/abstractions (things like the WebApi DelegateHandler) that would benefit from container validation?

For example: would a DbContext normally be expected to have some form of lifetime other than `transient?
Mar 27, 2014 at 9:29 AM
Other examples are global filters in both Web API and MVC. Unfortunately it will be impossible for the container to detect if they are registered as global filter or not.
Mar 27, 2014 at 9:33 AM
Edited Apr 15, 2014 at 10:35 AM
Another source of problems is WCF where instances that are registered as PerWcfOperation actually live as long as the service is configured in WCF (which can be PerCall, PerSession or Single (yuck!)). Single just means that the service class becomes a singleton, which of course has impact on the lifetime of its dependencies. This comes back to this issue.
Mar 30, 2014 at 9:47 PM
Edited Apr 15, 2014 at 10:35 AM
The problems with WCF can partly be solved by letting the RegisterWcfServices extention method register types that are marked as Single, register as singleton. This allows the diagnostic services to spot any non singleton dependencies.

The 2.5.1 release of the SimpleInjector.Integration.Wcf assembly partly fixes this problem letting the RegisterWcfServices extension method register WCF service classes that are marked with InstanceContextMode.Single as Singleton in the container.