Wrapper for any Serialize package
Install packages:
Startup:
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//configuration
services.AddSerialization(o =>
{
o.UseBinaryGo();
o.UseNewtonsoftJson();
});
}
}
Usage:
using Common.Models;
using EasyMicroservices.Serialization.Interfaces;
using Microsoft.AspNetCore.Mvc;
[Route("api/[controller]")]
[ApiController]
public class DIController : ControllerBase
{
private readonly IBinarySerializationProvider _binarySerialization;
private readonly ITextSerializationProvider _textSerialization;
public DIController(IBinarySerializationProvider binarySerialization, ITextSerializationProvider textSerialization)
{
_binarySerialization = binarySerialization;
_textSerialization = textSerialization;
}
[Route("Serialize")]
[HttpGet]
public IActionResult Serialize()
{
Customer model = new Customer() { Age = 51, FirstName = "Elon", LastName = "Musk" };
var result = _textSerialization.Serialize(model);
var binary = _binarySerialization.Serialize(model);
return Ok(result);
}
}