Easily scaffold Grpc and or REST API for non-production scenarios.
- Create any model with a
partial class
and add relevant Attribute for ex:RestApi
[GrpcApi] // Whicherver is desired
[RestApi]
public partial class Product
{
public Guid Id { get; set; }
}
- Configure
KurzSharp
by 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")));
🎉 You API is ready, Run project and open Swagger Docs.
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
override
the required ones.OnBeforeCreate
OnBeforeAllRead
OnBeforeRead
OnBeforeUpdate
OnBeforeDelete
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;
}
}