Skip to content

Latest commit

 

History

History
77 lines (57 loc) · 3.22 KB

README.md

File metadata and controls

77 lines (57 loc) · 3.22 KB

Serialization

Wrapper for any Serialize package

Install packages:

  1. Core package:

    NuGet

  2. Use package:

    NuGet Badge

    NuGet Badge

    NuGet Badge

    NuGet Badge

    NuGet Badge Badge

    NuGet Badge

    NuGet Badge

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);
    }
}

Line Coverage Status