Currently we only serialize things as json. Ideally, we need an interface or something that you can implement (or pass as a parameter in the attribute) to provide a custom serialization mechanism.
The interface will be something like
public interface IPersistentComponentStateSerializer
{
Task Persist(Type type, object instance, IBufferWriter buffer);
void Restore(Type type, ReadOnlySequence<byte> data);
}
- Restore needs to be synchronous to avoid tearing on the UI.
- We don't want
byte[] based APIs, as we want to minimize additional allocations if possible and we don't want to give the serializer the responsibility of allocating buffers.
Implementation Plan for Serialization Extensibility in Persistent Component State
Sample Registration
// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
// Register custom serializer as Singleton
builder.Services.AddSingleton<IPersistentComponentStateSerializer<User>, CustomUserSerializer>();
var app = builder.Build();
Task Checklist
1. Define the Serializer Interface
2. Update PooledArrayBufferWriter Integration
3. Modify Persistent State Value Provider
5. Maintain Backward Compatibility
6. Add Tests
Currently we only serialize things as json. Ideally, we need an interface or something that you can implement (or pass as a parameter in the attribute) to provide a custom serialization mechanism.
The interface will be something like
byte[]based APIs, as we want to minimize additional allocations if possible and we don't want to give the serializer the responsibility of allocating buffers.Implementation Plan for Serialization Extensibility in Persistent Component State
Sample Registration
Task Checklist
1. Define the Serializer Interface
2. Update PooledArrayBufferWriter Integration
3. Modify Persistent State Value Provider
5. Maintain Backward Compatibility
6. Add Tests