Ejemplo n.º 1
0
        public static void UseFhirServerController(this IServiceCollection services, IFhirSystemServiceSTU3 systemService)
        {
            NetCoreApi.Startup._systemService = systemService;
            services.AddMvc(options =>
            {
                // remove the default formatters
                options.InputFormatters.RemoveType <Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter>();
                // Note there is a default implementation of the json patch in here, need to know how to hook into that
                options.InputFormatters.RemoveType <Microsoft.AspNetCore.Mvc.Formatters.JsonPatchInputFormatter>();

                options.InputFormatters.Add(new XmlFhirInputFormatter());
                options.InputFormatters.Add(new JsonFhirInputFormatter());
                options.InputFormatters.Add(new BinaryFhirInputFormatter());

                options.OutputFormatters.Clear();
                options.OutputFormatters.Add(new XmlFhirOutputFormatter());
                options.OutputFormatters.Add(new JsonFhirOutputFormatter(ArrayPool <char> .Shared));
                options.OutputFormatters.Add(new BinaryFhirOutputFormatter());

                // and include our custom content negotiator filter to handle the _format parameter
                // (from the FHIR spec:  http://hl7.org/fhir/http.html#mime-type )
                // https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters
                options.Filters.Add(new FhirFormatParameterFilter());
            });
        }
Ejemplo n.º 2
0
        public static void Register(HttpConfiguration config, IFhirSystemServiceSTU3 systemService)
        {
            _systemService = systemService;

            // https://github.com/azzlack/Microsoft.AspNet.WebApi.MessageHandlers.Compression
            config.MessageHandlers.Insert(0, new OwinServerCompressionHandler(4096, new GZipCompressor(), new DeflateCompressor()));

            config.MessageHandlers.Add(new InterceptBodyHandler());
            config.MessageHandlers.Add(new MediaTypeHandler());

            config.MapHttpAttributeRoutes();

            // remove existing formatters
            config.Formatters.Clear();

            // Hook custom formatters
            config.Formatters.Add(new XmlFhirFormatter());
            config.Formatters.Add(new JsonFhirFormatter());
            config.Formatters.Add(new BinaryFhirFormatter());

            // Add these formatters in case our own throw exceptions, at least you
            // get a decent error message from the default formatters then.
            config.Formatters.Add(new JsonMediaTypeFormatter());
            config.Formatters.Add(new XmlMediaTypeFormatter());

            // EK: Remove the default BodyModel Validator. We don't need it,
            // and it makes the Validation framework throw a null reference exception
            // when the body empty. This only surfaces when calling a DELETE with no body,
            // while the action method has a parameter for the body.
            config.Services.Replace(typeof(IBodyModelValidator), null);
        }