![]() |
VOOZH | about |
dotnet add package RxDBDotNet --version 1.2.1
NuGet\Install-Package RxDBDotNet -Version 1.2.1
<PackageReference Include="RxDBDotNet" Version="1.2.1" />
<PackageVersion Include="RxDBDotNet" Version="1.2.1" />Directory.Packages.props
<PackageReference Include="RxDBDotNet" />Project file
paket add RxDBDotNet --version 1.2.1
#r "nuget: RxDBDotNet, 1.2.1"
#:package RxDBDotNet@1.2.1
#addin nuget:?package=RxDBDotNet&version=1.2.1Install as a Cake Addin
#tool nuget:?package=RxDBDotNet&version=1.2.1Install as a Cake Tool
👁 NuGet Version
👁 NuGet Downloads
👁 codecov
RxDBDotNet is a powerful .NET library that implements the RxDB replication protocol, enabling real-time data synchronization between RxDB clients and .NET servers using GraphQL and Hot Chocolate. It extends the standard RxDB replication protocol with .NET-specific enhancements.
Install the RxDBDotNet package via NuGet:
dotnet add package RxDBDotNet
Implement IReplicatedDocument for your document type:
public class Workspace : IReplicatedDocument
{
public required Guid Id { get; init; }
public required string Name { get; set; }
public required DateTimeOffset UpdatedAt { get; set; }
public required bool IsDeleted { get; set; }
public List<string>? Topics { get; set; }
}
Implement the document service:
public class WorkspaceService : IReplicatedDocumentService<Workspace>
{
// Implement the required methods
// ...
}
Configure services in Program.cs:
// Add your document service to the DI container
builder.Services
.AddSingleton<IReplicatedDocumentService<Workspace>, WorkspaceService>();
// Configure the Hot Chocolate GraphQL server
builder.Services
.AddGraphQLServer()
// Mutation conventions must be enabled for replication to work
.AddMutationConventions()
// Enable RxDBDotNet replication services
.AddReplication()
// Register the document to be replicated
.AddReplicatedDocument<Workspace>()
.AddInMemorySubscriptions();
var app = builder.Build();
app.UseWebSockets();
app.MapGraphQL();
app.Run();
RxDBDotNet supports policy-based security using the Microsoft.AspNetCore.Authorization infrastructure.
Configuration:
Define authorization policies:
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("IsWorkspaceAdmin", policy =>
policy.RequireClaim("WorkspaceRole", "Admin"));
options.AddPolicy("CanReadWorkspace", policy =>
policy.RequireClaim("WorkspaceRole", "Admin", "Reader"));
});
Configure security options for documents:
builder.Services
.AddGraphQLServer()
.AddReplicatedDocument<Workspace>(options =>
{
options.Security = new SecurityOptions()
.RequirePolicyToRead("CanReadWorkspace")
.RequirePolicyToWrite("IsWorkspaceAdmin");
});
RxDBDotNet supports subscription topics for fine-grained control over real-time updates.
Usage:
Specify topics when creating or updating a document:
var liveDoc = new LiveDoc
{
Id = Guid.NewGuid(),
Content = "New document content",
UpdatedAt = DateTimeOffset.UtcNow,
IsDeleted = false,
WorkspaceId = workspaceId,
Topics = new List<string> { $"workspace-{workspaceId}" }
};
await documentService.CreateAsync(liveDoc, CancellationToken.None);
Subscribe to specific topics:
subscription StreamLiveDocs {
streamLiveDoc(topics: ["workspace-123e4567-e89b-12d3-a456-426614174000"]) {
documents {
id
content
updatedAt
isDeleted
workspaceId
}
checkpoint {
updatedAt
lastDocumentId
}
}
}
Configure custom error types to provide more detailed error information to clients:
builder.Services
.AddGraphQLServer()
.AddReplicatedDocument<User>(options =>
{
options.Errors = new List<Type>
{
typeof(UserNameTakenException),
typeof(InvalidUserNameException)
};
});
RxDBDotNet supports configuring multiple authentication schemes for GraphQL subscriptions over WebSocket connections. This feature provides flexibility in token validation and supports scenarios where you need to handle tokens from different authentication sources.
By default, RxDBDotNet uses the standard JWT Bearer authentication scheme ("Bearer"). You can use this with minimal configuration:
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = // ... your token validation parameters
});
builder.Services
.AddGraphQLServer()
.AddMutationConventions()
.AddReplication() // Uses default Bearer scheme
You can configure multiple authentication schemes to validate subscription tokens:
// Configure multiple JWT Bearer schemes
builder.Services
.AddAuthentication()
.AddJwtBearer("Bearer", options =>
{
options.Audience = "DefaultAudience";
options.TokenValidationParameters = // ... default scheme parameters
})
.AddJwtBearer("CustomScheme", options =>
{
options.Audience = "CustomAudience";
options.TokenValidationParameters = // ... custom scheme parameters
});
// Configure RxDBDotNet to use both schemes
builder.Services
.AddGraphQLServer()
.AddMutationConventions()
.AddReplication(options =>
{
options.Security
.TryAddSubscriptionAuthenticationScheme("CustomScheme");
// The default "Bearer" scheme is already included
});
When a client attempts to establish a WebSocket connection, RxDBDotNet will:
The subscription authentication system fully supports OpenID Connect configuration, including dynamic key retrieval and rotation:
builder.Services
.AddAuthentication()
.AddJwtBearer("OidcScheme", options =>
{
options.Authority = "https://your-identity-provider.com";
options.Audience = "your-api";
options.RequireHttpsMetadata = true;
});
builder.Services
.AddGraphQLServer()
.AddMutationConventions()
.AddReplication(options =>
{
options.Security
.TryAddSubscriptionAuthenticationScheme("OidcScheme");
});
The system will automatically:
Clients should include the JWT token in the WebSocket connection initialization:
const client = createClient({
url: 'ws://your-api/graphql',
connectionParams: {
headers: {
Authorization: `Bearer ${jwtToken}`
}
}
});
The subscription authentication system provides detailed error information:
The example directory contains a full-stack application demonstrating RxDBDotNet usage in a real-world scenario:
example/livedocs-client: A Next.js frontend app using RxDB with RxDBDotNetexample/LiveDocs.GraphQLApi: A .NET backend API using RxDBDotNetexample/LiveDocs.AppHost: A .NET Aspire AppHost for running the full stackFor more details on running and debugging the example client app, see the .
To run the example application, you'll need the following installed:
Note:
- Docker Desktop is required to run the Redis and SQL Server instances used by the example application.
- For detailed instructions on installing .NET Aspire and its dependencies, please refer to the official .NET Aspire setup documentation.
Ensure you have .NET Aspire installed and Docker Desktop is running on your machine.
Navigate to the example/LiveDocs.AppHost directory.
Run the following command:
dotnet run --launch-profile full-stack
Open the .NET Aspire dashboard (typically at http://localhost:15041).
Access the frontend at http://localhost:3001 and the GraphQL API at http://localhost:5414/graphql.
RxDBDotNet implements the RxDB replication protocol with additional error handling conventions:
Document-Level Replication: Supports the git-like replication model for local changes and server state merging.
Transfer-Level Protocol:
Pull query with checkpoint-based iteration.Push mutation for client-side writes and conflict detection.Stream subscription for real-time updates.Checkpoint Iteration: Supports efficient data synchronization using checkpoints.
Data Layout:
UpdatedAt).IsDeleted flag) instead of physical deletion.Conflict Handling: Implements server-side conflict detection during push operations.
Offline-First Support: Allows clients to continue operations offline and sync when back online.
Advanced Error Handling: Utilizes Hot Chocolate GraphQL mutation conventions for detailed error information.
RxDBDotNet requires custom implementations for RxDB clients due to its advanced features and integration with Hot Chocolate GraphQL. These customizations include:
Custom Query Builders:
Subscription Topics and Pull Stream Builder: Enables fine-grained control over real-time updates, allowing clients to subscribe to specific subsets of data.
These customizations enable RxDB clients to effectively communicate with RxDBDotNet backends, leveraging advanced features like filtered synchronization and topic-based real-time updates.
For detailed examples and explanations of these custom implementations, including code snippets and usage guidelines, please refer to the .
RxDBDotNet implements a crucial security measure to prevent potential issues with untrusted client-side clocks. The server always overwrites the UpdatedAt timestamp with its own server-side timestamp for document creation or update requests. This ensures:
This security measure is implemented in the MutationResolver<TDocument> class. Developers should be aware that any client-provided UpdatedAt value will be ignored and replaced with the server's timestamp.
Important: While the IReplicatedDocument interface defines UpdatedAt with both a getter and a setter, developers should not manually set this property in their application code. Always rely on the server to set the correct UpdatedAt value during replication operations. The setter is present solely to allow the server to overwrite the timestamp as a security measure.
We welcome contributions to RxDBDotNet! Here's how you can contribute:
git checkout -b feature/amazing-feature).git push origin feature/amazing-feature).Please ensure your code meets our coding standards and includes appropriate tests and documentation.
We use squash merges for all pull requests. The pull request title will be used as the commit message in the main branch, so it must follow the Conventional Commits syntax.
Please refer to our for more detailed guidelines.
This project is licensed under the MIT License - see the file for details.
This project adheres to the Contributor Covenant . By participating, you are expected to uphold this code.
Please see our for information on reporting security vulnerabilities and which versions are supported.
Ready to dive in? Get started or contribute to shape the future of .NET-based data replication!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.