DynamicConsume 2.0.1
dotnet add package DynamicConsume --version 2.0.1
NuGet\Install-Package DynamicConsume -Version 2.0.1
<PackageReference Include="DynamicConsume" Version="2.0.1" />
paket add DynamicConsume --version 2.0.1
#r "nuget: DynamicConsume, 2.0.1"
// 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 | Versions 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. |
-
net6.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.