Skip to content

petervdpas/EntityBlast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EntityBlast 🗄️

NuGet NuGet Downloads License

EntityBlast

EntityBlast is a sibling in the Blast family of NuGet packages. It provides a single typed entity-store abstraction (IEntityStore<T>) backed by InMemory, JSON file, EF Core, or Dapper — pick the one you need or mix them. It also ships a runtime EF model: register types at startup via IDynamicTypeRegistry and DynamicDbContext picks them up in OnModelCreating, so you can persist types that didn't exist at compile time (for example, types produced by AssemblyBlast).

EntityBlast and AssemblyBlast are independent. Neither depends on the other. EntityBlast does not depend on UtilBlast.

What it gives you

  • IEntityStore<T> — a small async contract: Save, Insert (batch), Load, Delete, List, with composite-key overloads.
  • Four backendsInMemoryEntityStore<T>, FileEntityStore<T> (JSON files in a directory), DbEntityStore<T> (EF Core), DapperEntityStore<T> (auto-creates a table from the type's properties).
  • [IsKeyField] / [IsDisplayField] / [IsRequired] — opt-in property annotations. When [IsKeyField] is absent, key detection falls back to configurable name matches (default: Id).
  • IDynamicTypeRegistry + DynamicDbContext — register Type objects at startup; the EF context exposes a DbSet<T> for each registered type. Useful when types are emitted at runtime.
  • IDynamicEntityResolver — resolve an IEntityStore<T> for a Type you only know at runtime, with an in-memory fallback if no store is registered for that type.

Install

dotnet add package EntityBlast

Quick start — InMemory

public class Person
{
    [IsKeyField]
    public string Id { get; set; } = "";
    public string Name { get; set; } = "";
}

var store = new InMemoryEntityStore<Person>();
await store.SaveAsync("p1", new Person { Id = "p1", Name = "Ada" });

var loaded = await store.LoadAsync("p1");

Quick start — File (JSON)

var keySelector = DynamicKeySelectorFactory.CreateSelector<Person>(["Id"]);
var store = new FileEntityStore<Person>("./data", keySelector);

await store.SaveAsync(new[] { "p1" }, new Person { Id = "p1", Name = "Ada" });

Quick start — Dapper

Func<IDbConnection> open = () =>
{
    var c = new SqliteConnection("Data Source=app.db");
    c.Open();
    return c;
};

var store = new DapperEntityStore<Person>(open, fallbackKeyNames: ["Id"]);
// CREATE TABLE IF NOT EXISTS Person (...) runs on construction

Quick start — EF Core with runtime types

builder.Services.AddEntityBlast(o =>
{
    o.RegisterDbStore = true;
    o.ConfigureDynamicDb = db => db.UseSqlite("Data Source=app.db");
});

// Anywhere with access to IDynamicTypeRegistry:
registry.RegisterType(typeof(Person));   // or a runtime-emitted Type

License

MIT, see LICENSE.txt.

About

Typed entity-store abstraction for .NET, InMemory, JSON file, EF Core, Dapper. Sibling in the Blast family.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages