CapitalSix.AspNetCore.Realtime
1.0.0
dotnet add package CapitalSix.AspNetCore.Realtime --version 1.0.0
NuGet\Install-Package CapitalSix.AspNetCore.Realtime -Version 1.0.0
<PackageReference Include="CapitalSix.AspNetCore.Realtime" Version="1.0.0" />
paket add CapitalSix.AspNetCore.Realtime --version 1.0.0
#r "nuget: CapitalSix.AspNetCore.Realtime, 1.0.0"
// Install CapitalSix.AspNetCore.Realtime as a Cake Addin #addin nuget:?package=CapitalSix.AspNetCore.Realtime&version=1.0.0 // Install CapitalSix.AspNetCore.Realtime as a Cake Tool #tool nuget:?package=CapitalSix.AspNetCore.Realtime&version=1.0.0
AspNetCore.Realtime
AspNetCore.Realtime is a module, which provides realtime updates on data changes. Modified data in any database is automatically published the updates to a web client.
It is a publish and subscribe system between client (Javascript) and server (AspNetCore). It vastly simplifies the client programming.
This system is based on the same publish and subscribe system that MeteorJS uses. The client side has a mini-mongo database that contains the data that you are subscibed to. All updates to the local database are automatically synchronized with the server and changes at the server side are synchronized with everyone who's subscribed to the data.
Advantages of this approach are:
- Less programming logic at the client side, because data is automatically updated
- Less data traffic, because only updated data is exchanged
- Data updates are instantly visible on multiple clients without refreshing
The AspNetCore.Realtime is database independent, because it works from an API point of view. Simple calls added to your API endpoint, will publish updates, inserts, deletes to all listening clients.
Example:
[HttpPost]
[Authorize]
[Consumes("application/json")]
public async Task<IActionResult> AddAsync([FromBody] PersonDto personDto, CancellationToken cancellationToken)
{
var person = _mapper.Map<Person>(personDto);
// Find the account claim
var accountClaim = User.Claims.SingleOrDefault(c => c.Type == DemoClaimTypes.AccountId);
if (accountClaim == null) return Unauthorized();
// Get accountId from accountClaim
var accountId = accountClaim.Value;
// Use repository to create a new person record
var addedPerson = await _personRepository.AddAsync(
accountId,
person,
cancellationToken);
var addedPersonDto = _mapper.Map<PersonDto>(addedPerson);
// After successful creation, trigger AspNetCore.Realtime to
// synchronize all clients where authorization fits. In this
// example the authorization is based on users with that
// belong to the same account
_ = _collectionTrigger.OnInsertedAsync(
CollectionName,
addedPersonDto,
session => session.Claims.ValidateAccount(accountId),
cancellationToken);
return Ok(addedPersonDto);
}
Every client that is subscribed to a dataset will get updates, within your own defined authorization scope ofcourse, even if you're not the initiator of the action.
For example user1 adds a record to the database, than user1 gets to see the new record, but also user2 and user4.
Installation
Install Nuget package AspNetCore.Realtime
Add-Package AspNetCore.Realtime
Install npm package react-realtime
npm install --save react-realtime
Usage
AspNetCore startup add:
builder.Services
.AddRealtime()
.AddCollections();
...
app.UseRealtime();
Or with authentication:
builder.Services
.AddRealtime()
.AddJwtAuthentication(authBuilder =>
{
authBuilder.Audience = builder.Configuration["Jwt:Audience"] ?? string.Empty;
authBuilder.Issuer = builder.Configuration["Jwt:Issuer"] ?? string.Empty;
authBuilder.Secret = builder.Configuration["Jwt:Key"] ?? string.Empty;
})
.AddCollections();
...
app.UseRealtime();
AddRealtime
This registeres the publish and subscribe system
AddCollections
This method registers all collections that you want to publish. It scans all assemblies for classes which are derived from EntityCollection and are decorated with the Publication attribute. The publication attribute defines the name of the publication.
The EntityCollection contains 2 types. One public model (Dto) and one private model. It uses Automapper for any model mapping.
The public models are used for transfer between client and server. The private model is used internally by you. For example for storing in a database.
[Publication("persons")]
public class PersonCollection : EntityCollection<PersonDto, Person>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- Swashbuckle.AspNetCore (>= 6.4.0)
- System.IdentityModel.Tokens.Jwt (>= 8.0.2)
- System.Linq.Async (>= 6.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CapitalSix.AspNetCore.Realtime:
Package | Downloads |
---|---|
CapitalSix.AspNetCore.Realtime.Authentication.Jwt
Jwt authentication module for AspNetCore.Realtime |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 69 | 3/9/2025 |