IXC.ORM
1.0.6
dotnet add package IXC.ORM --version 1.0.6
NuGet\Install-Package IXC.ORM -Version 1.0.6
<PackageReference Include="IXC.ORM" Version="1.0.6" />
<PackageVersion Include="IXC.ORM" Version="1.0.6" />
<PackageReference Include="IXC.ORM" />
paket add IXC.ORM --version 1.0.6
#r "nuget: IXC.ORM, 1.0.6"
#:package IXC.ORM@1.0.6
#addin nuget:?package=IXC.ORM&version=1.0.6
#tool nuget:?package=IXC.ORM&version=1.0.6
Esse ORM foi criado com o intuito de facilitar o consumo de dados da API oficial do IXC Provedor.
Essa biblioteca não faz parte das bibliotecas oficiais da IXCsoft e foi desenvolvida de forma independente e sem fins lucrativos.
⬇️ Download
dotnet add package IXC.ORM
Após o download, certifique-se de que a dependência foi adicionada ao seu .csproj...
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
...
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IXC.ORM" Version="1.0.6" />
...
</ItemGroup>
...
🖥️ Variáveis de Ambiente
No
appsettings.jsonouappsettings.Development.json.
{
"IxcOrm": {
"AccessToken": "token gerado dentro do IXC",
"ServerDomain": "dominiodoseuixc.com.br"
}
}
No
docker-compose.yaml.
services:
sua-aplicacao:
build:
context: .
dockerfile: Dockerfile
image: sua-imagem-docker:0.0.0
environment:
# Obtendo as variáveis a partir de um .env
- IxcOrm__AccessToken=${IXC_ACCESS_TOKEN}
- IxcOrm__ServerDomain=${IXC_SERVER_DOMAIN}
...
Siga o exemplo abaixo para carregar o ambiente da biblioteca em tempo de execução.
using DotNet.IXC.ORM.Config; // Sem isso, builder.Services.AddIxcOrmEnvironment(config => {}); não funciona!!!
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddIxcOrmEnvironment(config =>
{
var accessToken = builder.Configuration.GetValue<string>("IxcOrm:AccessToken")
?? throw new InvalidOperationException("A variável IxcOrm:AccessToken não está configurada.");
var serverDomain = builder.Configuration.GetValue<string>("IxcOrm:ServerDomain")
?? throw new InvalidOperationException("A variável IxcOrm:ServerDomain não está configurada.");
config.SetupAccessToken(accessToken);
config.SetupServerDomain(serverDomain);
});
👨💻 Implementação
Convertendo resultados com o auxílio da classe
IxcRecord.
using DotNet.IXC.ORM;
using System.Text.Json.Serialization;
public class Cliente : IxcRecord
{
[JsonPropertyName("razao")]
public string Razao { get; set; } = string.Empty;
[JsonPropertyName("cnpj_cpf")]
public string CnpjCpf { get; set; } = string.Empty;
}
Utilizando a classe
IxcOrmpara poder enviar as requisições ao o seu IXC Provedor.
using DotNet.IXC.ORM;
public class ClienteOrm : IxcOrm
{
public static ClienteOrm NewOrm()
{
return new ClienteOrm();
}
private ClienteOrm() : base("cliente") { } // Define a tabela "cliente" como alvo das consultas.
public async Task<List<Cliente>?> FindByCnpjOrCpf(string cnpjOrCpf)
{
IxcOrmResponse<Cliente> response = await Where("cnpj_cpf")
.Like(cnpjOrCpf)
.GetAsync<Cliente>();
if (response is null || response.Total == 0)
{
return null;
}
return response.Records;
}
}
Ciar uma classe derivada de
IxcOrm, como no exemplo acima, permitirá que você a utilize como no exemplo abaixo...
// EXEMPLO DE COMO IMPLEMENTAR UM POSSÍVEL MÉTODO "GET" EM UM CONTROLLER DA SUA API
[HttpGet("{cnpjOrCpf}")]
public async Task<IActionResult> FindByCnpjOrCpf([FromRoute] string cnpjOrCpf)
{
using var orm = ClienteOrm.NewOrm();
try
{
var clientes = await orm.FindByCnpjOrCpf(cnpjOrCpf);
if (clientes is null)
{
return NotFound();
}
return Ok(clientes);
}
catch (IxcOrmResponseException e)
{
return Problem(detail: e.Message, statusCode: 500);
}
catch (IxcOrmRequestException e)
{
return Problem(detail: e.Message, statusCode: 400);
}
}
Você não é obrigado a seguir à risca os exemplos acima... ☝🏻
Eles servem apenas como orientação sobre como utilizar esta biblioteca!
Contribuições
Contribuições são sempre bem-vindas!
Se você conhece uma maneira melhor de fazer algo, por favor, me avise!
Ou sinta-se a vontade para enviar um novo PR!
At.te,
<b>Felipe S. Carmo</b>.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- HtmlAgilityPack (>= 1.12.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.