Fewbit.EntityFramework.CrudApi
1.0.0-beta-5
dotnet add package Fewbit.EntityFramework.CrudApi --version 1.0.0-beta-5
NuGet\Install-Package Fewbit.EntityFramework.CrudApi -Version 1.0.0-beta-5
<PackageReference Include="Fewbit.EntityFramework.CrudApi" Version="1.0.0-beta-5" />
paket add Fewbit.EntityFramework.CrudApi --version 1.0.0-beta-5
#r "nuget: Fewbit.EntityFramework.CrudApi, 1.0.0-beta-5"
// Install Fewbit.EntityFramework.CrudApi as a Cake Addin #addin nuget:?package=Fewbit.EntityFramework.CrudApi&version=1.0.0-beta-5&prerelease // Install Fewbit.EntityFramework.CrudApi as a Cake Tool #tool nuget:?package=Fewbit.EntityFramework.CrudApi&version=1.0.0-beta-5&prerelease
EntityFramework.CrudApi
The "EntityFramework.CrudApi" project is a library that enables the easy exposure of an Entity Framework DbContext as a REST API, all with just a single line of code. Leveraging the capabilities of the Minimal API approach in DotNet Core, it uses reflection to dynamically create and expose REST resources (GET, PUT, POST, DELETE) for each Entity/Class mapped through Entity Framework. This approach streamlines the process of creating REST endpoints, requiring only a few lines of code.
Features
Minimal API Integration: The library seamlessly integrates with DotNet Core's Minimal API approach, providing a straightforward way to expose Entity Framework DbContext as RESTful endpoints.
Reflection-based Resource Creation: Through reflection, the library dynamically generates REST resources for each Entity/Class mapped using Entity Framework. This eliminates the need for manually defining endpoints, making the process more efficient.
Support for CRUD Operations: The generated API supports standard CRUD operations - GET, PUT, POST, and DELETE, allowing for easy manipulation of data stored in the underlying DbContext.
Simplified Endpoint Creation: With just a single line of code, developers can expose an entire DbContext through REST APIs, significantly reducing the amount of boilerplate code required.
Getting Started
Installation
To use the "EntityFramework.CrudApi" library, you can install it via NuGet Package Manager:
dotnet add package Fewbit.EntityFramework.CrudApi --version 1.0.0-alpha
Usage
Add a reference to the library in your project.
In your startup or configuration code, include the following line to expose your DbContext through REST APIs:
// Before build app
builder.Services.AddEntityFrameworkCrudApi(typeof(Program).Assembly);
// After app was built
app.MapCrudApiRoutes<MyDbContext>().WithOpenApi();
Replace MyDbContext with the name of your Entity Framework DbContext.
That's it! Your DbContext is now accessible through REST endpoints.
Example
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddConsole();
builder.Services.Configure<JsonOptions>(options =>
{
options.SerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});
// Add DbContext
builder.Services.AddDbContext<MyDbContext>();
// Add Validators
builder.Services.AddValidatorsFromAssemblyContaining<Program>();
// Add AutoMapper
builder.Services.AddAutoMapper(typeof(Program));
// Add MediatR
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<Program>());
// Customize CrudApi
// Add CrudApi
builder.Services.AddEntityFrameworkCrudApi(typeof(Program).Assembly);
// Add Problems mapping for error output
builder.Services.AddProblemDetails();
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<MyDbContext>();
db.Database.EnsureCreated();
}
// ConfigureRouteHandlerBuilder the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.UseExceptionHandler();
}
app.UseHttpsRedirection();
app.MapCrudApiRoutes<MovieStore>().WithOpenApi();
app.Run();
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. |
-
net8.0
- AutoMapper (>= 13.0.1)
- Fewbit.EntityFramework.CrudApi.Abstractions (>= 1.0.0-beta-5)
- FluentValidation (>= 11.9.1)
- Humanizer (>= 2.14.1)
- Microsoft.EntityFrameworkCore (>= 8.0.4)
- Scrutor (>= 4.2.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.0.0-beta-5 | 60 | 5/14/2024 |
1.0.0-beta-4 | 52 | 5/14/2024 |
1.0.0-beta-3 | 64 | 4/23/2024 |
1.0.0-beta-2 | 52 | 4/22/2024 |
1.0.0-beta-1 | 84 | 1/19/2024 |
1.0.0-alpha-9 | 54 | 1/19/2024 |
1.0.0-alpha-8 | 56 | 1/19/2024 |
1.0.0-alpha-7 | 57 | 1/18/2024 |
1.0.0-alpha-6 | 66 | 1/17/2024 |
1.0.0-alpha-5 | 59 | 1/17/2024 |
1.0.0-alpha-4 | 67 | 1/16/2024 |
1.0.0-alpha-3 | 61 | 1/16/2024 |
1.0.0-alpha-2 | 61 | 1/16/2024 |
1.0.0-alpha-10 | 55 | 1/19/2024 |
1.0.0-alpha-1 | 63 | 1/15/2024 |
1.0.0-alpha | 64 | 1/15/2024 |