Easily scaffold non-production APIs in any or all of following Architectures:
- GraphQl (HotChocolate)
- Grpc (Code First protobuf-net.Grpc)
- REST (ASP.NET Core Controllers)
and Explore Data with:
AdminDashboard (using Blazor, Radzen Table and MudBlazor UI)
Minimum required dotnet version: .NET8
- Create any model with a
partial classand add relevant Attribute for ex:RestApi
[GrpcApi] // Whicherver is desired
[RestApi]
[GraphQlApi]
[AdminDashboard]
public partial class Product
{
public Guid Id { get; set; }
}- Configure
KurzSharpby default Data is stored in Memory with Entity FrameworkUseInMemoryDatabase
services.AddKurzSharp();For Database add relavent Db package for Entity Framework and configure KurzSharp similar way to Entity Framework
config. (ex: PostgresDb):
services.AddKurzSharp(o => o.UseNpgsql(configuration.GetConnectionString("ProductsDb")));Map Routes and Services:
app.MapKurzSharpServices();🎉 You API is ready, Run project and open Swagger Docs.
For GraphQl API open Bana Cake Pop at http://localhost:5114/graphql
For REST or Grpc API open Swagger at http://localhost:5114/swagger
For Admin Dashboard UI open http://localhost:5114/KurzSharp/ or sub page with /{EntityName}s.
For more information please check examples/TestApi
- Hook into process to control how/what information on Entity is modified/observed with following hooks. Hook
automatically attached the Model, just
overridethe required ones.TDto OnBeforeCreate(TDto dto)IEnumerable<TDto> OnBeforeCreate(IEnumerable<TDto> dtos)IQueryable<TDto> OnBeforeRead(IQueryable<TDto> dtos)TDto OnBeforeRead(TDto dto)TDto OnBeforeUpdate(TDto dto)Enumerable<TDto> OnBeforeUpdate(IEnumerable<TDto> dto)TDto OnBeforeDelete(TDto dto)IEnumerable<TDto> OnBeforeDelete(IEnumerable<TDto> dto)
Ex:
[RestApi]
public partial class Product
{
private readonly ILogger<Product> _logger;
public Product(ILogger<Product> logger)
{
_logger = logger;
}
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public override ProductDto OnBeforeCreate(ProductDto dto)
{
_logger.LogInformation("DI is working...");
return dto;
}
}When a KurzSharp attributes like RestApi, GraphQlApi or GrpcApi is added on some Model class, it creates a new
Dto entity which has the same properties as the Model. The Model is used to store data through
Entity Framework Core and Dto is sent over the wire through API. It also takes attributes from the properties and
puts them on the Dto's properties for example: JsonIgnoreAttribute.


