Skip to content

Commit b213b86

Browse files
committed
Commit all pending workspace changes
1 parent 79b894f commit b213b86

18 files changed

Lines changed: 1162 additions & 244 deletions

File tree

BLite.Server.sln

Lines changed: 0 additions & 36 deletions
This file was deleted.

global.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net10.0</TargetFramework>
@@ -7,15 +7,22 @@
77
<ImplicitUsings>enable</ImplicitUsings>
88
<RootNamespace>BLite.Sample</RootNamespace>
99
<AssemblyName>BLite.Sample</AssemblyName>
10+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
1314
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.*" />
1415
<PackageReference Include="Scalar.AspNetCore" Version="2.*" />
16+
<PackageReference Include="BLite.SourceGenerators" Version="3.6.4">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
1520
</ItemGroup>
1621

1722
<ItemGroup>
1823
<ProjectReference Include="..\..\src\BLite.Client\BLite.Client.csproj" />
24+
<ProjectReference Include="..\..\src\BLite.Client.SourceGenerators\BLite.Client.SourceGenerators.csproj"
25+
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
1926
</ItemGroup>
2027

2128
</Project>

samples/BLite.Sample/Product.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// BLite.Sample — Product entity
2+
// Copyright (C) 2026 Luca Fabbri — AGPL-3.0
3+
4+
using BLite.Bson;
5+
6+
namespace BLite.Sample;
7+
8+
/// <summary>
9+
/// Product catalog entity. The source generator discovers it through the
10+
/// <see cref="ProductCatalogContext.Products"/> property and produces:
11+
/// • a C-BSON serialiser/deserialiser (<c>ProductCatalogContext_*_Mappers.BLite_Sample_ProductMapper</c>)
12+
/// • the <c>InitializeCollections</c> override that wires the collection property
13+
/// Default collection name: "products" (lowercase class name + "s").
14+
/// </summary>
15+
public class Product
16+
{
17+
[BsonId]
18+
public ObjectId Id { get; set; }
19+
20+
public string Name { get; set; } = string.Empty;
21+
22+
public string Category { get; set; } = string.Empty;
23+
24+
public double Price { get; set; }
25+
26+
public int Stock { get; set; }
27+
28+
public bool Active { get; set; } = true;
29+
30+
public DateTime CreatedAt { get; set; }
31+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// BLite.Sample — ProductCatalogContext
2+
// Copyright (C) 2026 Luca Fabbri — AGPL-3.0
3+
//
4+
// Remote document context. Two source generators cooperate at compile time:
5+
//
6+
// BLite.SourceGenerators (from the BLite core repo):
7+
// - Analyses the Products property and generates the C-BSON mapper for Product
8+
// - Generates the InitializeCollections() override that assigns Products
9+
//
10+
// BLite.Client.SourceGenerators (from this repo):
11+
// - Generates: ProductCatalogContext(BLiteClient client) : base()
12+
// - Generates: CreateCollection<TId,T> override → client.GetDocumentCollection(mapper)
13+
//
14+
// Usage:
15+
// services.AddSingleton(sp => new ProductCatalogContext(sp.GetRequiredService<BLiteClient>()));
16+
// ...
17+
// app.MapGet("/products", async (ProductCatalogContext db, CancellationToken ct) =>
18+
// TypedResults.Ok(await db.Products.AsQueryable().ToListAsync(ct)));
19+
20+
using BLite.Bson;
21+
using BLite.Core;
22+
using BLite.Core.Collections;
23+
using BLite.Core.Metadata;
24+
25+
namespace BLite.Sample;
26+
27+
public partial class ProductCatalogContext : DocumentDbContext
28+
{
29+
public IDocumentCollection<ObjectId, Product> Products { get; set; } = null!;
30+
31+
protected override void OnModelCreating(ModelBuilder modelBuilder)
32+
{
33+
base.OnModelCreating(modelBuilder);
34+
35+
modelBuilder.Entity<Product>()
36+
.HasKey(p => p.Id);
37+
}
38+
}

0 commit comments

Comments
 (0)