Created
July 4, 2012 12:36
-
-
Save tugberkugurlu/3047119 to your computer and use it in GitHub Desktop.
DefaultServices class in ASP.NET Web API project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Class needs references to large number of types.")] | |
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "We're registering the ValidationCache to be disposed by the HttpConfiguration.")] | |
public DefaultServices(HttpConfiguration configuration) | |
{ | |
if (configuration == null) | |
{ | |
throw Error.ArgumentNull("configuration"); | |
} | |
_configuration = configuration; | |
// Initialize the dictionary with all known service types, even if the list for that service type is | |
// empty, because we will throw if the developer tries to read or write unsupported types. | |
SetSingle<IActionValueBinder>(new DefaultActionValueBinder()); | |
SetSingle<IApiExplorer>(new ApiExplorer(configuration)); | |
SetSingle<IAssembliesResolver>(new DefaultAssembliesResolver()); | |
SetSingle<IBodyModelValidator>(new DefaultBodyModelValidator()); | |
SetSingle<IContentNegotiator>(new DefaultContentNegotiator()); | |
SetSingle<IDocumentationProvider>(null); // Missing | |
SetMultiple<IFilterProvider>(new ConfigurationFilterProvider(), | |
new ActionDescriptorFilterProvider()); | |
SetSingle<IHostBufferPolicySelector>(null); | |
SetSingle<IHttpActionInvoker>(new ApiControllerActionInvoker()); | |
SetSingle<IHttpActionSelector>(new ApiControllerActionSelector()); | |
SetSingle<IHttpControllerActivator>(new DefaultHttpControllerActivator()); | |
SetSingle<IHttpControllerSelector>(new DefaultHttpControllerSelector(configuration)); | |
SetSingle<IHttpControllerTypeResolver>(new DefaultHttpControllerTypeResolver()); | |
SetSingle<ITraceManager>(new TraceManager()); | |
SetSingle<ITraceWriter>(null); | |
// This is a priority list. So put the most common binders at the top. | |
SetMultiple<ModelBinderProvider>(new TypeConverterModelBinderProvider(), | |
new TypeMatchModelBinderProvider(), | |
new KeyValuePairModelBinderProvider(), | |
new ComplexModelDtoModelBinderProvider(), | |
new ArrayModelBinderProvider(), | |
new DictionaryModelBinderProvider(), | |
new CollectionModelBinderProvider(), | |
new MutableObjectModelBinderProvider()); | |
SetSingle<ModelMetadataProvider>(new DataAnnotationsModelMetadataProvider()); | |
SetMultiple<ModelValidatorProvider>(new DataAnnotationsModelValidatorProvider(), | |
new DataMemberModelValidatorProvider(), | |
new InvalidModelValidatorProvider()); | |
// This is an ordered list,so put the most common providers at the top. | |
SetMultiple<ValueProviderFactory>(new QueryStringValueProviderFactory(), | |
new RouteDataValueProviderFactory()); | |
ModelValidatorCache validatorCache = new ModelValidatorCache(new Lazy<IEnumerable<ModelValidatorProvider>>(() => this.GetModelValidatorProviders())); | |
configuration.RegisterForDispose(validatorCache); | |
SetSingle<IModelValidatorCache>(validatorCache); | |
_serviceTypesSingle = new HashSet<Type>(_defaultServicesSingle.Keys); | |
_serviceTypesMulti = new HashSet<Type>(_defaultServicesMulti.Keys); | |
// Reset the caches and the known dependency scope | |
ResetCache(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment