[Perf] #1550 - Turn ModelMetadataProvider into a singleton

The modelmetadataprovider does significant reflection caching, which shows
up as a hotspot. It's only of our most commonly used services, so not only
do a TON of instances get created, they are very heavy-weight because of
the two ConcurrentDictionary instances they have.
This commit is contained in:
Ryan Nowak 2015-02-05 13:55:09 -08:00
parent e94cec51fa
commit 3c380bc38e
1 changed files with 3 additions and 1 deletions

View File

@ -79,7 +79,9 @@ namespace Microsoft.AspNet.Mvc
// Dataflow - ModelBinding, Validation and Formatting
yield return describe.Transient<IModelMetadataProvider, DataAnnotationsModelMetadataProvider>();
// The DataAnnotationsModelMetadataProvider does significant caching of reflection/attributes
// and thus needs to be singleton.
yield return describe.Singleton<IModelMetadataProvider, DataAnnotationsModelMetadataProvider>();
yield return describe.Transient<IInputFormatterSelector, DefaultInputFormatterSelector>();
yield return describe.Scoped<IInputFormattersProvider, DefaultInputFormattersProvider>();