1
votes

I would like to use BSON in my self-host Web API. I'am using .Net Core 2.0 and autofac. In every each tutorial I see that I need add BsonMediaTypeFormatter to formatters, but I don't have WebApiConfig.cs with HttpConfiguration. In my Web API I have only startup.cs and program.cs.

In startup.cs I have two methods:

public IServiceProvider ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)

How can I set BSON formatter?

1
Do you have a reason to prefer BSON instead JSON? - Marco Dal Zovo
Yes "For serializing binary data, such as an image file, BSON is smaller than JSON, because the binary data is not base64-encoded." - Drakoo

1 Answers

1
votes
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc()
            .AddBsonSerializerFormatters();
    }
}