/*
         * 私有构造函数
         * **/
        private HttpConfiguration(HttpConfiguration configuration, HttpControllerSettings settings)
        {
            _routes                  = configuration.Routes;
            _filters                 = configuration.Filters;
            _messageHandlers         = configuration.MessageHandlers;
            _properties              = configuration.Properties;
            _dependencyResolver      = configuration.DependencyResolver;
            IncludeErrorDetailPolicy = configuration.IncludeErrorDetailPolicy;

            // per-controller settings
            Services              = settings.IsServiceCollectionInitialized ? settings.Services : configuration.Services;
            _formatters           = settings.IsFormatterCollectionInitialized ? settings.Formatters : configuration.Formatters;
            ParameterBindingRules = settings.IsParameterBindingRuleCollectionInitialized ? settings.ParameterBindingRules : configuration.ParameterBindingRules;

            // Use the original configuration's initializer so that its Initialize()
            // will perform the same logic on this clone as on the original.
            Initializer = configuration.Initializer;

            // create a new validator cache if the validator providers have changed
            if (settings.IsServiceCollectionInitialized &&
                !settings.Services.GetModelValidatorProviders().SequenceEqual(configuration.Services.GetModelValidatorProviders()))
            {
                ModelValidatorCache validatorCache = new ModelValidatorCache(new Lazy <IEnumerable <ModelValidatorProvider> >(() => Services.GetModelValidatorProviders()));
                settings.Services.Replace(typeof(IModelValidatorCache), validatorCache);
            }
        }
Пример #2
0
        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();
        }
Пример #3
0
        public DefaultServices(ProcessorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            this.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.
            DefaultCommandHandlerSelector commandHandlerSelector = new DefaultCommandHandlerSelector(this.configuration);

            this.SetSingle <ICommandHandlerSelector>(commandHandlerSelector);
            this.SetSingle <ICommandHandlerDescriptorProvider>(commandHandlerSelector);
            this.SetSingle <ICommandHandlerActivator>(new DefaultCommandHandlerActivator());
            this.SetSingle <ICommandHandlerTypeResolver>(new DefaultCommandHandlerTypeResolver());

            // Events
            DefaultEventHandlerSelector eventHandlerSelector = new DefaultEventHandlerSelector(this.configuration);

            this.SetSingle <IEventHandlerSelector>(eventHandlerSelector);
            this.SetSingle <IEventHandlerDescriptorProvider>(eventHandlerSelector);
            this.SetSingle <IEventHandlerActivator>(new DefaultEventHandlerActivator());
            this.SetSingle <IEventHandlerTypeResolver>(new DefaultEventHandlerTypeResolver());
            this.SetSingle <ICommandHandlerInvoker>(new DefaultCommandHandlerInvoker());
            this.SetSingle <IEventHandlerInvoker>(new DefaultEventHandlerInvoker());

            this.SetMultiple <IFilterProvider>(new ConfigurationFilterProvider(), new HandlerFilterProvider());

            this.SetSingle <IAssembliesResolver>(new DefaultAssembliesResolver());

            this.SetSingle <IProxyBuilder>(new DefaultProxyBuilder());
            this.SetSingle <IInterceptionProvider>(new DefaultInterceptionProvider(this.configuration));
            this.SetMultiple <IInterceptor>(new IInterceptor[0]);
            this.SetSingle <ICommandValidator>(new DefaultCommandValidator());

            this.SetSingle <ModelMetadataProvider>(new DataAnnotationsModelMetadataProvider());
            this.SetSingle <IModelFlattener>(new DefaultModelFlattener());

            this.SetSingle <IPrincipalProvider>(new DefaultPrincipalProvider());

            this.SetSingle <IEventStore>(new NullEventStore());

            // Validation
            this.SetMultiple <ModelValidatorProvider>(new DataAnnotationsModelValidatorProvider());
            ModelValidatorCache validatorCache = new ModelValidatorCache(new Lazy <ModelValidatorProvider[]>(this.GetModelValidatorProviders));

            this.SetSingle <IModelValidatorCache>(validatorCache);

            // Tracing
            this.SetSingle <ITraceManager>(new TraceManager());
            this.SetSingle <ITraceWriter>(null);

            this.SetSingle <ICommandWorker>(new DefaultCommandWorker(configuration));
            this.SetSingle <IEventWorker>(new DefaultEventWorker(configuration));
            this.SetSingle <IMessageProcessor>(null);

            this.SetSingle <IQueryService>(new DefaultQueryService());

            // Exception handling
            this.SetSingle <IExceptionHandler>(null);
            this.SetMultiple <IExceptionLogger>();

            // Queuing
            this.SetSingle <ICommandReceiver>(null);
            this.SetSingle <ICommandSender>(null);

            this.serviceTypesSingle = new HashSet <Type>(this.defaultServicesSingle.Keys);
            this.serviceTypesMulti  = new HashSet <Type>(this.defaultServicesMulti.Keys);

            // Reset the caches and the known dependency scope
            this.ResetCache();
        }