GenericApiNetCore.Abstract
2023.11.17.938
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package GenericApiNetCore.Abstract --version 2023.11.17.938
NuGet\Install-Package GenericApiNetCore.Abstract -Version 2023.11.17.938
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="GenericApiNetCore.Abstract" Version="2023.11.17.938" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenericApiNetCore.Abstract --version 2023.11.17.938
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GenericApiNetCore.Abstract, 2023.11.17.938"
#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 GenericApiNetCore.Abstract as a Cake Addin #addin nuget:?package=GenericApiNetCore.Abstract&version=2023.11.17.938 // Install GenericApiNetCore.Abstract as a Cake Tool #tool nuget:?package=GenericApiNetCore.Abstract&version=2023.11.17.938
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
GenericApiNetCore
Demo
Description
Create CURD api for aspnet core 6.0 quickly:
public interface IApiMethods<T>
{
Task<IApiResult<List<T>>> CreateAsync(CreateRequest<T> entitysRequest);
Task<IApiResult<List<T>>> UpdateAsync(UpdateRequest<T> entitysRequest);
Task<IApiResult<List<T>>> PagingAsync(PagingRequest<T> pageRequest);
Task<IApiResult<int>> DeleteAsync(DeleteRequest<T> idsRequest);
}
How to use
A. Server API
Install Package
GenericApiNetCore.Server
PM> Install-Package GenericApiNetCore.Server
Define you Entity model
//[ApiInfoRequest("api/product")] public class Product { public Guid Id { get; set; } = Guid.NewGuid(); public string? Name { get; set; } = DateTime.Now.ToString(); }
Implement method for IRepositoryMethods<Product>
public abstract class RepositoryMethods<T> : IRepositoryMethods<T> { readonly List<T> entities = new List<T>(); public async Task<List<T>> CreateAsync(List<T> entitysRequest) { entities.AddRange(entitysRequest); return entitysRequest; } public async Task<int> DeleteAsync(Guid[] idsRequest) { entities.RemoveAll(q => idsRequest.Contains(GetId(q))); return idsRequest.Length; } public abstract Guid GetId(T entity); public async Task<List<T>> PagingAsync(int pageRequest) { return entities.Skip((pageRequest - 1) * 5).Take(pageRequest * 5).ToList(); } public async Task<List<T>> UpdateAsync(List<T> entitysRequest) { await DeleteAsync(entitysRequest.Select(q => GetId(q)).ToArray()); await CreateAsync(entitysRequest); return entitysRequest; } }
public class ProductRepositoryMethods : RepositoryMethods<Product> { public override Guid GetId(Product entity) => entity.Id; }
Config Dependency injection
Program.cs
builder.Services.AddSingleton<IRepositoryMethods<Product>, ProductRepositoryMethods>();
Create api
using GenericApiNetCore.Samples.Entities; using GenericApiNetCore.ServerLib; using Microsoft.AspNetCore.Mvc; namespace GenericApiNetCore.WebApi.Controllers { [RouteGeneric(typeof(Product))] public class ProductController : GenericControllerBase<Product> { public ProductController(IRepositoryMethods<Product> repositoryMethods) : base(repositoryMethods) { } } }
B. Client call API
Just call api service
using GenericApiNetCore.ClientLib;
using GenericApiNetCore.Samples.Entities;
var baseAddress = new Uri("https://localhost:7013/");
using var client = new ClientApiMethod<Product>(baseAddress);
var data = await client.PagingAsync(new PagingRequest<Product>() { Payload = 1 });
return data;
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on GenericApiNetCore.Abstract:
Package | Downloads |
---|---|
GenericApiNetCore.ClientLib
Package Description |
|
GenericApiNetCore.ServerLib
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2023.11.17.1028 | 296 | 11/17/2023 |
2023.11.17.1024 | 157 | 11/17/2023 |
2023.11.17.1020 | 167 | 11/17/2023 |
2023.11.17.947 | 162 | 11/17/2023 |
2023.11.17.938 | 172 | 11/17/2023 |
2023.11.17.935 | 186 | 11/17/2023 |
2023.11.17.423 | 126 | 11/17/2023 |
1.0.1 | 134 | 11/16/2023 |
1.0.0 | 121 | 11/16/2023 |