Getting Started
ZibStack.NET is a collection of source generators for .NET. Each package is independent — install only what you need. Start at Tier 1 (drop-in, zero architectural buy-in) and move deeper only if it fits your project — see the Three tiers overview for orientation.
Quick Install
Section titled “Quick Install”dotnet add package ZibStack.NET.Logdotnet add package ZibStack.NET.Aopdotnet add package ZibStack.NET.Validationdotnet add package ZibStack.NET.Dtodotnet add package ZibStack.NET.Validationdotnet add package ZibStack.NET.EntityFrameworkdotnet add package Microsoft.EntityFrameworkCore.SqliteTier 1 — Minimal drop-in example
Section titled “Tier 1 — Minimal drop-in example”Add one attribute to get structured logging, OpenTelemetry tracing, or both — no architectural changes.
using ZibStack.NET.Aop;
var builder = WebApplication.CreateBuilder(args);builder.Services.AddAop(); // registers built-in [Trace] handler
var app = builder.Build();app.Services.UseAop(); // bridges DI into the aspect runtimeapp.Run();using ZibStack.NET.Aop;
public class OrderService{ [Log] // structured entry/exit/exception logging [Trace] // OpenTelemetry span with parameter tags public async Task<Order> GetOrderAsync(int id) { // ... your code unchanged }
// Or, for the whole class: // [Log] [Trace] public class OrderService { ... }}You now have compile-time structured logging and OpenTelemetry spans with zero boilerplate. Wire an exporter (AddOpenTelemetry().WithTracing().AddOtlpExporter()) and you’re done.
Tier 3 — Minimal CRUD API example
Section titled “Tier 3 — Minimal CRUD API example”If you want the full-stack scaffold: define a model, add one attribute, and get a full REST API with database persistence. Note this moves a lot of code out of your hands — best for solo or small-team projects.
using ZibStack.NET.Dto;using ZibStack.NET.Validation;
[CrudApi][ZValidate]public partial class Player{ [DtoIgnore] public int Id { get; set; } [ZRequired] [ZMinLength(2)] public required string Name { get; set; } [ZRange(1, 100)] public int Level { get; set; } [ZEmail] public string? Email { get; set; }}using ZibStack.NET.EntityFramework;
[GenerateCrudStores]public class AppDbContext : DbContext{ public DbSet<Player> Players => Set<Player>(); public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }}var builder = WebApplication.CreateBuilder(args);builder.Services.AddDbContext<AppDbContext>(o => o.UseSqlite("Data Source=app.db"));builder.Services.AddAppDbContextCrudStores(); // auto-generatedbuilder.Services.ConfigureHttpJsonOptions(o => o.SerializerOptions.Converters.Add(new PatchFieldJsonConverterFactory()));
var app = builder.Build();using (var scope = app.Services.CreateScope()) scope.ServiceProvider.GetRequiredService<AppDbContext>().Database.EnsureCreated();
app.MapPlayerEndpoints(); // auto-generated: GET, POST, PATCH, DELETEapp.Run();That’s it. You now have:
| Endpoint | Method | Description |
|---|---|---|
/api/players | GET | List with pagination |
/api/players/{id} | GET | Get by ID |
/api/players | POST | Create with validation |
/api/players/{id} | PATCH | Partial update |
/api/players/{id} | DELETE | Delete |
All responses use ProblemDetails (RFC 9110) for errors, and PatchField for true partial updates.
What are Source Generators?
Section titled “What are Source Generators?”Source generators run at compile time and emit C# code into your project. No reflection, no runtime overhead, full IntelliSense support. The generated code is visible in obj/ — you can inspect exactly what’s produced.
Next Steps
Section titled “Next Steps”- Dto — CRUD API & DTOs — the full reference
- Full CRUD with SQLite Guide — step-by-step tutorial
- EntityFramework — auto-generated stores
- Log — zero-allocation logging