How do I enable BSON serialization in my ASP.NET core web interface?

I am new to ASP.NET Core and network programming in general. I have just successfully completed my first ASP.NET Core API based on RESTfull design principles. It currently uses JSON serialization to send responses (default for Visual Studio), but I'd like to try BSON. I have spent a day googling and I cannot find any examples of how to add a BSON serialization / deserialization server process. I came across several articles on how to do this on ASP.NET fullscreen where it has been included out of the box for several years (e.g .: https://docs.microsoft.com/en-us/aspnet/web-api/ overview / formats-and-model-binding / bson-support-in-web-api-21 and http://www.strathweb.com/2012/07/bson-binary-json-and-how-your-web- api-can-be-even-faster /), but nothing specifically related to ASP.NET core.

I hunted for the VS generated source files, hoping to find something similar to the full wireframe examples I linked, but nothing popped up at me as there was little similarity. Can anyone post (or link to) some code that shows how this is done in ASP.NET Core? Thanks a lot in advance.

+3


source to share


1 answer


You can use this formatter: https://github.com/WebApiContrib/WebAPIContrib.Core

Then add to startup.cs:



using WebApiContrib.Core.Formatter.Bson;

namespace MyApp
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
                .AddBsonSerializerFormatters();
        }
    }
}

      

+3


source







All Articles