Example #1
0
 public async Task WriteAsync(OutputFormatterContext context)
 {
     // Override using the selected encoding.
     context.SelectedEncoding = Encoding;
     var jsonFormatter = new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(),
                                                 indent: false);
     await jsonFormatter.WriteResponseBodyAsync(context);
 }
Example #2
0
        /// <inheritdoc />
        public void Setup(MvcOptions options)
        {
            // Set up ViewEngines
            options.ViewEngines.Add(typeof(RazorViewEngine));

            // Set up ModelBinding
            options.ModelBinders.Add(new TypeConverterModelBinder());
            options.ModelBinders.Add(new TypeMatchModelBinder());
            options.ModelBinders.Add(typeof(GenericModelBinder));
            options.ModelBinders.Add(new MutableObjectModelBinder());
            options.ModelBinders.Add(new ComplexModelDtoModelBinder());

            // Set up default output formatters.
            options.OutputFormatters.Add(new TextPlainFormatter());
            options.OutputFormatters.Add(new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(),
                                         indent: false));

            // Set up ValueProviders
            options.ValueProviderFactories.Add(new RouteValueValueProviderFactory());
            options.ValueProviderFactories.Add(new QueryStringValueProviderFactory());
            options.ValueProviderFactories.Add(new FormValueProviderFactory());
        }
Example #3
0
        /// <inheritdoc />
        public void Setup(MvcOptions options)
        {
            // Set up ViewEngines
            options.ViewEngines.Add(typeof(RazorViewEngine));

            // Set up ModelBinding
            options.ModelBinders.Add(new TypeConverterModelBinder());
            options.ModelBinders.Add(new TypeMatchModelBinder());
            options.ModelBinders.Add(new ByteArrayModelBinder());
            options.ModelBinders.Add(typeof(GenericModelBinder));
            options.ModelBinders.Add(new MutableObjectModelBinder());
            options.ModelBinders.Add(new ComplexModelDtoModelBinder());

            // Set up default output formatters.
            options.OutputFormatters.Add(new HttpNoContentOutputFormatter());
            options.OutputFormatters.Add(new TextPlainFormatter());
            options.OutputFormatters.Add(new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(),
                                                                 indent: false));
            options.OutputFormatters.Add(
                new XmlDataContractSerializerOutputFormatter(XmlOutputFormatter.GetDefaultXmlWriterSettings()));
            options.OutputFormatters.Add(
                new XmlSerializerOutputFormatter(XmlOutputFormatter.GetDefaultXmlWriterSettings()));

            // Set up default input formatters.
            options.InputFormatters.Add(new JsonInputFormatter());
            options.InputFormatters.Add(new XmlSerializerInputFormatter());
            options.InputFormatters.Add(new XmlDataContractSerializerInputFormatter());

            // Set up ValueProviders
            options.ValueProviderFactories.Add(new RouteValueValueProviderFactory());
            options.ValueProviderFactories.Add(new QueryStringValueProviderFactory());
            options.ValueProviderFactories.Add(new FormValueProviderFactory());

            // Set up validators
            options.ModelValidatorProviders.Add(new DataAnnotationsModelValidatorProvider());
            options.ModelValidatorProviders.Add(new DataMemberModelValidatorProvider());
        }
Example #4
0
 public JsonViewComponentResult([NotNull] object data)
 {
     Data = data;
     _jsonSerializerSettings = JsonOutputFormatter.CreateDefaultSettings();
 }
Example #5
0
        public static IEnumerable <IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
        {
            var describe = new ServiceDescriber(configuration);

            yield return(describe.Transient <IOptionsSetup <MvcOptions>, MvcOptionsSetup>());

            yield return(describe.Transient <IControllerFactory, DefaultControllerFactory>());

            yield return(describe.Singleton <IControllerActivator, DefaultControllerActivator>());

            yield return(describe.Singleton <IActionSelectorDecisionTreeProvider, ActionSelectorDecisionTreeProvider>());

            yield return(describe.Scoped <IActionSelector, DefaultActionSelector>());

            yield return(describe.Transient <IActionInvokerFactory, ActionInvokerFactory>());

            yield return(describe.Transient <IControllerAssemblyProvider, DefaultControllerAssemblyProvider>());

            yield return(describe.Transient <IActionDiscoveryConventions, DefaultActionDiscoveryConventions>());

            // The host is designed to be discarded after consumption and is very inexpensive to initialize.
            yield return(describe.Transient <IMvcRazorHost, MvcRazorHost>());

            yield return(describe.Singleton <ICompilationService, RoslynCompilationService>());

            yield return(describe.Singleton <IRazorCompilationService, RazorCompilationService>());

            yield return(describe.Singleton <IViewEngineProvider, DefaultViewEngineProvider>());

            yield return(describe.Scoped <ICompositeViewEngine, CompositeViewEngine>());

            yield return(describe.Singleton <IViewStartProvider, ViewStartProvider>());

            yield return(describe.Transient <IRazorView, RazorView>());

            yield return(describe.Singleton <IRazorPageActivator, RazorPageActivator>());

            // Virtual path view factory needs to stay scoped so views can get get scoped services.
            yield return(describe.Scoped <IRazorPageFactory, VirtualPathRazorPageFactory>());

            yield return(describe.Singleton <IFileInfoCache, ExpiringFileInfoCache>());

            yield return(describe.Transient <INestedProvider <ActionDescriptorProviderContext>,
                                             ReflectedActionDescriptorProvider>());

            yield return(describe.Transient <INestedProvider <ActionInvokerProviderContext>,
                                             ReflectedActionInvokerProvider>());

            yield return(describe.Singleton <IActionDescriptorsCollectionProvider,
                                             DefaultActionDescriptorsCollectionProvider>());

            yield return(describe.Transient <IModelMetadataProvider, DataAnnotationsModelMetadataProvider>());

            yield return(describe.Scoped <IActionBindingContextProvider, DefaultActionBindingContextProvider>());

            yield return(describe.Transient <IInputFormatterSelector, DefaultInputFormatterSelector>());

            yield return(describe.Scoped <IInputFormattersProvider, DefaultInputFormattersProvider>());

            yield return(describe.Transient <IModelBinderProvider, DefaultModelBindersProvider>());

            yield return(describe.Scoped <ICompositeModelBinder, CompositeModelBinder>());

            yield return(describe.Transient <IValueProviderFactoryProvider, DefaultValueProviderFactoryProvider>());

            yield return(describe.Scoped <ICompositeValueProviderFactory, CompositeValueProviderFactory>());

            yield return(describe.Transient <IOutputFormattersProvider, DefaultOutputFormattersProvider>());

            yield return(describe.Instance <JsonOutputFormatter>(
                             new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), indent: false)));

            // The IGlobalFilterProvider is used to build the action descriptors (likely once) and so should
            // remain transient to avoid keeping it in memory.
            yield return(describe.Transient <IGlobalFilterProvider, DefaultGlobalFilterProvider>());

            yield return(describe.Transient <INestedProvider <FilterProviderContext>, DefaultFilterProvider>());

            yield return(describe.Transient <IModelValidatorProviderProvider, DefaultModelValidatorProviderProvider>());

            yield return(describe.Scoped <ICompositeModelValidatorProvider, CompositeModelValidatorProvider>());

            yield return(describe.Scoped <IUrlHelper, UrlHelper>());

            yield return(describe.Transient <IViewComponentSelector, DefaultViewComponentSelector>());

            yield return(describe.Singleton <IViewComponentActivator, DefaultViewComponentActivator>());

            yield return(describe.Transient <IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>());

            yield return(describe.Transient <INestedProvider <ViewComponentInvokerProviderContext>,
                                             DefaultViewComponentInvokerProvider>());

            yield return(describe.Transient <IViewComponentHelper, DefaultViewComponentHelper>());

            yield return(describe.Transient <IAuthorizationService, DefaultAuthorizationService>());

            yield return(describe.Singleton <IClaimUidExtractor, DefaultClaimUidExtractor>());

            yield return(describe.Singleton <AntiForgery, AntiForgery>());

            yield return(describe.Singleton <IAntiForgeryAdditionalDataProvider,
                                             DefaultAntiForgeryAdditionalDataProvider>());

            yield return
                (describe.Describe(
                     typeof(INestedProviderManager <>),
                     typeof(NestedProviderManager <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return
                (describe.Describe(
                     typeof(INestedProviderManagerAsync <>),
                     typeof(NestedProviderManagerAsync <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return(describe.Transient <IHtmlHelper, HtmlHelper>());

            yield return
                (describe.Describe(
                     typeof(IHtmlHelper <>),
                     typeof(HtmlHelper <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return(describe.Transient <MvcMarkerService, MvcMarkerService>());
        }