DynamicConsume 2.0.1

dotnet add package DynamicConsume --version 2.0.1                
NuGet\Install-Package DynamicConsume -Version 2.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DynamicConsume" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DynamicConsume --version 2.0.1                
#r "nuget: DynamicConsume, 2.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DynamicConsume as a Cake Addin
#addin nuget:?package=DynamicConsume&version=2.0.1

// Install DynamicConsume as a Cake Tool
#tool nuget:?package=DynamicConsume&version=2.0.1                

Dynamic Consume

Purpose

This package was prepared to eliminate the code confusion experienced when consuming the API in a .Net Core application.

Installation

You can add the package to your project via the Nuget package manager or cli

dotnet add package DynamicConsume --version 1.0.1

Usage

After installing the package, you must first register for the service in the Program.cs file.

builder.Services.AddDynamicConsume("your url");

Afterwards, you can use it in the controller you will use by requesting it from the DI container.

The methods and parameters

Generic class methods


Task<List<T>> GetListAsync(string endpoint)
Task<T> GetByIdAsync(string endpoint, int id)
Task<List<T>> GetListByIdAsync(string endpoint, int id)
Task<int> PostAsync(string endpoint, object modelClass)
Task<int> PutAsync(string endpoint, object modelClass)
Task<int> DeleteAsync(string endpoint, int id)

Non generic class methods

Task<string> GetStringAsync(string endpoint)
Task<int> GetIntAsync(string endpoint)

Example Usage:


public class MyDataModel
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class MyService
{
    private readonly Consume<MyDataModel> _consume;

    public MyService(Consume<MyDataModel> consume)
    {
        _consume = consume;
    }

    public async Task<List<MyDataModel>> GetAllData()
    {
        return await _consume.GetListAsync("/data");
    }

    public async Task<MyDataModel> GetDataById(int id)
    {
        return await _consume.GetByIdAsync("/data", id);
    }

    public async Task<int> CreateData(MyDataModel model)
    {
        return await _consume.PostAsync("/data", model);
    }

    public async Task<int> UpdateData(MyDataModel model)
    {
        return await _consume.PutAsync("/data", model);
    }

    public async Task<int> DeleteData(int id)
    {
        return await _consume.DeleteAsync("/data", id);
    }
}

Development

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 109 6/17/2024
1.0.1 109 6/16/2024
1.0.0 105 6/16/2024