eQuantic.Core.Api.Crud
1.6.18
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 eQuantic.Core.Api.Crud --version 1.6.18
NuGet\Install-Package eQuantic.Core.Api.Crud -Version 1.6.18
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="eQuantic.Core.Api.Crud" Version="1.6.18" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add eQuantic.Core.Api.Crud --version 1.6.18
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: eQuantic.Core.Api.Crud, 1.6.18"
#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 eQuantic.Core.Api.Crud as a Cake Addin #addin nuget:?package=eQuantic.Core.Api.Crud&version=1.6.18 // Install eQuantic.Core.Api.Crud as a Cake Tool #tool nuget:?package=eQuantic.Core.Api.Crud&version=1.6.18
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
eQuantic.Core.Api.Crud Library
The eQuantic Core API CRUD provides all the implementation needed to publish CRUD APIs.
To install eQuantic.Core.Api.Crud, run the following command in the Package Manager Console
Install-Package eQuantic.Core.Api.Crud
Example of implementation
The data entities
[Table("orders")]
public class OrderData : EntityDataBase
{
[Key]
public string Id { get; set; } = string.Empty;
public DateTime Date { get; set; }
public virtual ICollection<OrderItemData> Items { get; set; } = new HashSet<OrderItemData>();
}
[Table("orderItems")]
public class OrderItemData : EntityDataBase, IWithReferenceId<OrderItemData, int>
{
[Key]
public int Id { get; set; }
public int OrderId { get; set; }
[ForeignKey(nameof(OrderId))]
public virtual OrderData? Order { get; set; }
[Required]
[MaxLength(200)]
public string Name { get; set; } = string.Empty;
}
The models
public class Order
{
public string Id { get; set; } = string.Empty;
public DateTime Date { get; set; }
}
public class OrderItem
{
public int Id { get; set; }
public int OrderId { get; set; }
public string Name { get; set; } = string.Empty;
}
The request models
public class OrderRequest
{
public DateTime? Date { get; set; }
}
public class OrderItemRequest
{
public string? Name { get; set; }
}
The mappers
public class OrderMapper : IMapper<OrderData, Order>, IMapper<OrderRequest, OrderData>
{
public Order? Map(OrderData? source)
{
return Map(source, new Order());
}
public Order? Map(OrderData? source, Order? destination)
{
if (source == null)
{
return null;
}
if (destination == null)
{
return Map(source);
}
destination.Id = source.Id;
destination.Date = source.Date;
return destination;
}
public OrderData? Map(OrderRequest? source)
{
return Map(source, new OrderData());
}
public OrderData? Map(OrderRequest? source, OrderData? destination)
{
if (source == null)
{
return null;
}
if (destination == null)
{
return Map(source);
}
destination.Date = source.Date ?? DateTime.UtcNow;
return destination;
}
}
The services
public interface IOrderService : ICrudService<Order, OrderRequest>
{
}
[MapCrudEndpoints]
public class OrderService : CrudServiceBase<Order, OrderRequest, OrderData, UserData>, IOrderService
{
public OrderService(IQueryableUnitOfWork unitOfWork, IMapperFactory mapperFactory) : base(unitOfWork, mapperFactory)
{
}
}
The Program.cs
var builder = WebApplication.CreateBuilder(args);
var assembly = typeof(Program).Assembly;
builder.Services.AddDbContext<ExampleDbContext>(opt =>
opt.UseInMemoryDatabase("ExampleDb"));
builder.Services.AddQueryableRepositories<ExampleUnitOfWork>(opt =>
{
opt.FromAssembly(assembly)
.AddLifetime(ServiceLifetime.Scoped);
});
builder.Services
.AddMappers(opt => opt.FromAssembly(assembly))
.AddTransient<IExampleService, ExampleService>()
.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
})
.AddFilterModelBinder()
.AddSortModelBinder();
builder.Services
.AddEndpointsApiExplorer()
.AddApiDocumentation(opt => opt.WithTitle("Example API"));
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseApiDocumentation();
}
app.UseHttpsRedirection();
app.UseRouting();
app.MapControllers();
app.MapCrud<Order, OrderRequest, IOrderService>();
app.Run();
or
...
app.MapAllCrud(opt => opt.FromAssembly(assembly));
app.Run();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- eQuantic.Core.Api (>= 1.6.17)
- eQuantic.Core.Application.Crud (>= 1.6.18)
- FluentValidation.AspNetCore (>= 11.3.0)
- Microsoft.AspNetCore.OpenApi (>= 7.0.14)
-
net8.0
- eQuantic.Core.Api (>= 1.6.17)
- eQuantic.Core.Application.Crud (>= 1.6.18)
- FluentValidation.AspNetCore (>= 11.3.0)
- Microsoft.AspNetCore.OpenApi (>= 8.0.2)
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 |
---|---|---|
1.7.19 | 145 | 11/9/2024 |
1.7.18 | 171 | 10/11/2024 |
1.7.17 | 124 | 10/4/2024 |
1.7.16 | 88 | 10/4/2024 |
1.7.15 | 96 | 10/3/2024 |
1.7.14 | 268 | 9/4/2024 |
1.7.13 | 116 | 9/2/2024 |
1.7.12 | 115 | 9/1/2024 |
1.7.11 | 127 | 8/25/2024 |
1.7.10 | 173 | 8/22/2024 |
1.7.9 | 99 | 8/2/2024 |
1.7.8 | 87 | 7/29/2024 |
1.7.7 | 78 | 7/28/2024 |
1.7.6 | 85 | 7/27/2024 |
1.7.5 | 114 | 7/23/2024 |
1.7.4 | 115 | 7/22/2024 |
1.7.3 | 164 | 6/26/2024 |
1.7.2 | 89 | 6/26/2024 |
1.7.1 | 170 | 5/31/2024 |
1.7.0 | 106 | 5/29/2024 |
1.6.26 | 145 | 5/18/2024 |
1.6.25 | 156 | 5/15/2024 |
1.6.24 | 82 | 5/14/2024 |
1.6.23 | 154 | 5/4/2024 |
1.6.22 | 120 | 5/4/2024 |
1.6.21 | 134 | 4/28/2024 |
1.6.20 | 133 | 4/21/2024 |
1.6.19 | 158 | 4/20/2024 |
1.6.18 | 116 | 4/20/2024 |
1.6.17 | 155 | 4/11/2024 |
1.6.16 | 150 | 4/11/2024 |
1.6.15 | 118 | 4/9/2024 |
1.6.14 | 137 | 4/4/2024 |
1.6.13 | 131 | 4/2/2024 |
1.6.12 | 164 | 3/21/2024 |
1.6.11 | 113 | 3/21/2024 |
1.6.10 | 126 | 3/18/2024 |
1.6.9 | 121 | 3/10/2024 |
1.6.8 | 131 | 2/18/2024 |
1.6.7 | 110 | 2/17/2024 |
1.6.6 | 104 | 2/14/2024 |
1.6.5 | 104 | 2/13/2024 |
1.6.4 | 122 | 2/12/2024 |
1.6.3 | 128 | 2/10/2024 |
1.6.2 | 115 | 2/10/2024 |
1.6.1 | 123 | 1/22/2024 |
1.6.0 | 196 | 12/21/2023 |
1.5.2 | 151 | 12/10/2023 |
1.5.1 | 136 | 12/5/2023 |
1.5.0 | 136 | 12/5/2023 |
1.4.0 | 138 | 12/3/2023 |
1.3.3 | 174 | 11/18/2023 |
1.3.2 | 160 | 11/18/2023 |
1.3.1 | 165 | 11/15/2023 |
1.3.0 | 71 | 11/15/2023 |
1.2.3 | 121 | 11/2/2023 |
1.2.2 | 87 | 11/2/2023 |
1.2.1 | 154 | 10/21/2023 |
1.2.0 | 84 | 10/21/2023 |
1.1.6 | 109 | 10/9/2023 |
1.1.5 | 96 | 10/7/2023 |
1.1.4 | 131 | 10/2/2023 |
1.1.3 | 95 | 10/1/2023 |
1.1.2 | 118 | 9/25/2023 |
1.1.1 | 94 | 9/24/2023 |
1.1.0 | 155 | 9/4/2023 |
1.0.14 | 208 | 8/13/2023 |
1.0.13 | 162 | 8/13/2023 |
1.0.12 | 164 | 8/13/2023 |
1.0.11 | 174 | 8/13/2023 |
1.0.10 | 169 | 8/8/2023 |
1.0.9 | 198 | 8/3/2023 |
1.0.8 | 171 | 7/30/2023 |
1.0.7 | 166 | 7/22/2023 |
1.0.6 | 173 | 7/21/2023 |
1.0.5 | 169 | 7/21/2023 |
1.0.4 | 179 | 7/20/2023 |
1.0.3 | 166 | 7/20/2023 |
1.0.2 | 184 | 7/19/2023 |
1.0.0.1 | 160 | 7/5/2023 |
1.0.0 | 157 | 7/5/2023 |
Generic CRUD endpoints for Entities