Lyo.Favorite.Postgres 2.0.0

dotnet add package Lyo.Favorite.Postgres --version 2.0.0
                    
NuGet\Install-Package Lyo.Favorite.Postgres -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lyo.Favorite.Postgres" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lyo.Favorite.Postgres" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Lyo.Favorite.Postgres" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lyo.Favorite.Postgres --version 2.0.0
                    
#r "nuget: Lyo.Favorite.Postgres, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lyo.Favorite.Postgres@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lyo.Favorite.Postgres&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Lyo.Favorite.Postgres&version=2.0.0
                    
Install as a Cake Tool

Lyo.Favorite.Postgres

Entity Framework Core store for Lyo.Favorite on PostgreSQL. Rows live in favorite.favorite (PostgresFavoriteOptions.Schema = "favorite"), and the package includes migrations. Favorites carry subject / actor (for_entity_* / from_entity_*). SaveAsync blocks a second active row for the same (tenant, ForEntity, FromEntity, context) tuple.

PostgresFavoriteStore implements IFavoriteStore and Lyo.Health.IHealth (HealthCheckName = "favorite-postgres"). Registering the store also exposes a database liveness probe.

Examples

Register the store

services.AddPostgresFavoriteStore(new PostgresFavoriteOptions {
    ConnectionString = "...",
    EnableAutoMigrations = true
});

appsettings.json

{
  "PostgresFavorite": {
    "ConnectionString": "Host=localhost;Database=favorite;...",
    "EnableAutoMigrations": true
  }
}

Bind from configuration

services.AddPostgresFavoriteStoreFromConfiguration(configuration);

A user favorites an article

await favoriteStore.SaveAsync(new FavoriteRecord {
    SubjectEntityType = "Article",
    SubjectEntityId = articleId.ToString(),
    ActorEntityType = "User",
    ActorEntityId = userId.ToString()
});

var isFavorited = await favoriteStore.IsFavoritedAsync(
    EntityRef.ForGuid("Article", articleId),
    EntityRef.ForGuid("User", userId));

var count = await favoriteStore.GetCountForEntityAsync(
    EntityRef.ForGuid("Article", articleId));

// Batch count multiple targets in one round-trip.
var counts = await favoriteStore.GetFavoriteCountsForEntitiesAsync(
    "Article", new[] { id1, id2, id3 });

Add a migration

export FAVORITE_CONNECTION_STRING="Host=localhost;Database=favorite;Username=postgres;Password=postgres"
dotnet ef migrations add MigrationName --project Plugins/Favorite/Lyo.Favorite.Postgres

Service registration

  • AddFavoriteDbContextFactory(Action<PostgresFavoriteOptions>) / AddFavoriteDbContextFactory(PostgresFavoriteOptions) register the IDbContextFactory<FavoriteDbContext> only.
  • AddFavoriteDbContextFactoryFromConfiguration(IConfiguration, string sectionName = PostgresFavoriteOptions.SectionName) does the same, bound from configuration. Default section: PostgresFavorite.
  • AddPostgresFavoriteStore(Action<PostgresFavoriteOptions>) / AddPostgresFavoriteStore(PostgresFavoriteOptions) register the DbContext factory and the IFavoriteStore singleton.
  • AddPostgresFavoriteStoreFromConfiguration(IConfiguration, string sectionName = PostgresFavoriteOptions.SectionName) registers the store by binding configuration.

From configuration

The same registration from configuration:

Building an EntityRef

Create refs with Lyo.EntityReference.Models.EntityRef, either generic or from strings:

// Generic: uses typeof(T).FullName, keys joined with ":"
var forArticle = EntityRef.For<Article>(articleId);
var fromUser = EntityRef.For<User>(userId);

// String-based
var forEntity = EntityRef.ForGuid("Article", articleGuid);
var fromEntity = EntityRef.ForKey("User", "123");

Tenant isolation

Every read and write on PostgresFavoriteStore takes an optional Guid? tenantId. TenancyResolver applies the policy in PostgresFavoriteOptions.Tenancy. When that is unset, it inherits EntityRefOptions.Mode. Because tenant_id is non-null, only SingleTenantDefault and MultiTenantStrict are valid. Construction rejects SystemOnly. Every query gets a WhereTenant filter, so one tenant's favorites cannot appear in another. The policy matrix and an appsettings.json snippet live in Lyo.EntityReference.Postgres.

{
  "PostgresFavorite": {
    "ConnectionString": "Host=localhost;Database=lyo;...",
    "Tenancy": { "Mode": "MultiTenantStrict" }
  }
}

Database schema

  • favorite.favorite. EntityRelationEntityBase: id (uuid), subject/actor columns (for_entity_type, for_entity_id, from_entity_type, from_entity_id, nullable varchar 128/256), tenant_id, context, visibility, created_at, expires_at, deleted_at, deleted_by_type, deleted_by_id, and metadata (jsonb).

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Configuration (direct, lyo)
  • Lyo.EntityReference.Models (direct, lyo)
  • Lyo.EntityReference.Postgres (direct, lyo)
  • Lyo.Exceptions (direct, lyo)
  • Lyo.Favorite (direct, lyo)
  • Lyo.Health (direct, lyo)
  • Lyo.Postgres (direct, lyo)
  • Microsoft.EntityFrameworkCore 10.0.5 (direct, microsoft)
  • Microsoft.EntityFrameworkCore.Design 10.0.5 (direct, microsoft)
  • Lyo.Common.Core (transitive, lyo)
  • Microsoft.Bcl.AsyncInterfaces 10.0.5 (transitive, microsoft, netstandard2.0)
  • Microsoft.EntityFrameworkCore.Relational 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Configuration.Binder 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Hosting.Abstractions 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Options 10.0.5 (transitive, microsoft)
  • Microsoft.Extensions.Options.ConfigurationExtensions 10.0.5 (transitive, microsoft)
  • Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3 (transitive, third-party)
  • System.Memory 4.6.3 (transitive, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 (transitive, microsoft, netstandard2.0)
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 35 9/9/2026
1.0.13 92 8/25/2026
1.0.11 85 8/23/2026
1.0.9 91 8/22/2026
1.0.6 89 8/20/2026
1.0.4 100 8/20/2026
1.0.3 88 8/19/2026
1.0.2 87 8/19/2026
1.0.1 88 8/18/2026
1.0.0 100 8/16/2026