Releases: Cysharp/MagicOnion
Ver.5.0.1
What's Changed
- ReadMe: use minimal api template by @neuecc in #592
- Fix preprocessor conditions for Unity by @mayuki in #594
- chore: Apply Testcontainers for .NET best practices by @HofmeisterAn in #593
- Make StructLayout of DynamicArgumentTuples to LayoutKind.Auto by @mayuki in #595, #596
- Rewriting to Top-level statements style. by @mayuki in #597
New Contributors
- @HofmeisterAn made their first contribution in #593
Full Changelog: 5.0.0...5.0.1
Ver.5.0.0
Highlights
Update supporting platforms
- Bump supported Unity version to 2020.3 (LTS) or later (C# 8.0)
- Add support for .NET 7 and drop support for .NET Core 3.1, .NET 5 on servers
Adopt to .NET 7 and drop support for .NET Core 3.1, .NET 5 on servers #573
MagicOnion now supports .NET 7 and we drop support for .NET Core 3.1 and .NET 5 on servers.
- MagicOnion.Server supports only .NET 7 and .NET 6.
- MagicOnion.Client continues to support .NET Standard 2.x.
- If the client application which built/run on .NET 5 or .NET Core 3.1 runtime, it still can depend on the package for .NET Standard.
Non-Generic UnaryResult #579
Non-generic UnaryResult
is the return type of a service method that does not return a value. It replaces UnaryResult<Nil>
, which is similar to Task
and ValueTask
.
// Shared interface:
public interface IMyService : IService<IMyService>
{
UnaryResult MethodAsync(int arg0);
}
// Server-side:
public class MyService : ServiceBase<IMyService>, IMyService
{
public async UnaryResult MethodAsync(int arg0)
{
// Do something ...
// The method does not return any value. (like void, ValueTask, Task)
}
}
// Client-side:
await client.MethodAsync(1234);
Breaking changes
UnaryResult
has changed from static class
to struct
.
Allow ValueTask as a return type of the hub method. #583
MagicOnion 5.0 allows ValueTask
and ValueTask<T>
as a return type of the hub method. Previously, only Task
wereTask<T>
was allowed.
public interface IMyHub : IStreamingHub<IMyHub, IMyHubReceiver>
{
ValueTask FooAsync();
ValueTask<int> BarAsync();
}
Rework Server-side Filter APIs #552
Introduce IMagicOnionServiceFilter
, IStreamingHubFilter
The filter implementation changes from overriding attributes to implementing interfaces.
IMagicOnionServiceFilter
IStreamingHubFilter
IMagicOnionFilterFactory<T>
IMagicOnionOrderedFilter
This makes for a more flexible implementation, such as implementing both Unary filter and StreamingHub filter.
public class MyDualFilterAttribute : Attribute, IMagicOnionServiceFilter, IStreamingHubFilter, IMagicOnionOrderedFilter
{
public int Order { get; set; } = int.MaxValue;
ValueTask IMagicOnionServiceFilter.Invoke(ServiceContext context, Func<ServiceContext, ValueTask> next) { ... }
ValueTask IStreamingHubFilter.Invoke(StreamingHubContext context, Func<StreamingHubContext, ValueTask> next) { ... }
}
public class MyFilterAttribute : Attribute, IMagicOnionFilterFactory<IMagicOnionServiceFilter>, IMagicOnionOrderedFilter
{
public int Order { get; set; } = int.MaxValue;
public IMagicOnionServiceFilter CreateInstance(IServiceProvider serviceProvider)
=> new FilterImpl();
class FilterImpl : IMagicOnionServiceFilter
{
public ValueTask Invoke(ServiceContext context, Func<ServiceContext, ValueTask> next) { ... }
}
}
This changes MagicOnionFilterAttribute
, StreamingHubFilterAttribute
as follows:
// 4.x or earlier
public abstract class MagicOnionFilterAttribute : Attribute { ... }
public abstract class StreamingHubFilterAttribute : Attribute { ... }
// 5.0
public abstract class MagicOnionFilterAttribute : Attribute, IMagicOnionServiceFilter, IMagicOnionOrderedFilter { ... }
public abstract class StreamingHubFilterAttribute : Attribute, IStreamingHubFilter, IMagicOnionOrderedFilter { ... }
These have methods for implementation and can continue to be overridden.
Breaking changes
IMagicOnionFilterFactory<T>
has been moved underMagicOnion.Server.Filters
namespace.
Minor changes
- Use ServiceProvider and ActivatorUtilities to create an instance of filter or filter factory
- Specifying the implicit order of filters:
[Manually ordered filters] -> [Global Filters] -> [Class Filters] -> [Method Filters]
- The filters have
int.MaxValue
as the implicit order by default.
- The filters have
Read and write directly to the buffer using IBufferWriter when calling Unary #496
Read and write directly to the buffer using IBufferWriter when calling Unary.
Unary requests can be processed up to 5-10% more efficiently.
Breaking changes
- Remove
request
/response
parameter fromIMagicOnionLogger
- Remove
MagicOnionLogToLoggerWithDataDump
,MagicOnionLogToLoggerWithNamedDataDump
- Change the signature of
SetRawRequest
/GetRawRequest
frombyte[]
toobject
Rework {Server,Client,Duplex}Streaming #558
Change {Server,Client,Duplex}Streaming message processing on the server to IBufferWriter-based.
Breaking changes
- Remove
data
parameter fromIMagicOnionLogger.WriteToStream
,IMagicOnionLogger.ReadFromStream
Rework MagicOnionClient #530
MagicOnionClient client now uses IBufferWriter<T>
.
Marshaller wrapper API for encryption will be worked on in a separate PR.
Improvements
- More efficient memory usages
- Use buffers directly for serialization to reduce unnecessary byte allocation.
- DynamicClientBuilder and MagicOnionGenerator produce very similar code generation.
Breaking changes
- Bump supported Unity version to 2020.3 (LTS) or later (C# 8.0)
RequestMutator
andResponseMutator
are no longer supported.- We plan to introduce a new wrapper API for Marshaller.
Task<UnaryResult<T>>
is no longer supported as a return type of Unary method.- Use
UnaryResult<T>
instead.
- Use
moc
(MagicOnion.Generator) is no longer published to GitHub Releases.- We recommend that the generator be used with .NET CLI Tool.
Extensible message serialization #577
MagicOnion uses MessagePack for serialization by default, but it also provides extension points to customize serialization.
It allows for customization, such as encryption and the using of serializers other than MessagePack.
Breaking changes
- Client: MagicOnionClient and StreamingHubClient now receives
IMagicOnionSerializerProvider
instead ofMessagePackSerializerOptions
. - Server: Use
MagicOnionOptions.MessageSerializer
instead ofMagicOnionOptions.SerializerOptions
New APIs
public interface IMagicOnionSerializerProvider
{
IMagicOnionSerializer Create(MethodType methodType, MethodInfo? methodInfo);
}
public interface IMagicOnionSerializer
{
void Serialize<T>(IBufferWriter<byte> writer, in T? value);
T? Deserialize<T>(in ReadOnlySequence<byte> bytes);
}
public static class MagicOnionSerializerProvider
{
public static IMagicOnionSerializerProvider Default { get; set; } = MessagePackMagicOnionSerializerProvider.Default;
}
Use ModuleInitializer for automatic registration on .NET 5+ #578
Use ModuleInitializer for automatic registration on .NET 5+. When an application running on .NET 5+ uses a generated client, MagicOnionInitializer.Register()
is automatically called.
Notable changes
Option --no-use-unity-attr
is obsoleted, please use --disable-auto-register
instead.
Support for serialization using MemoryPack #590
Adds support for serialization using MemoryPack. (Preview)
Set MemoryPackMagicOnionSerializerProvider
to MagicOnionSerializerProvider
on the client and server to serialize using MemoryPack.
MagicOnionSerializerProvider.Default = MemoryPackMagicOnionSerializerProvider.Instance;
// or
await StreamingHubClient.ConnectAsync<IMyHub, IMyHubReceiver>(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
MagicOnionClient.Create<IMyService>(channel, MemoryPackMagicOnionSerializerProvider.Instance);
Using with Code Generator
If you want to use MagicOnion.Generator (moc), you need to specify --serializer MemoryPack
as an option.
The generated code will use MemoryPack instead of MessagePack.
The application must also call MagicOnionMemoryPackFormatterProvider.RegisterFormatters()
on startup.
What's Changed
Breaking Changes
- Rework MagicOnionClient by @mayuki in #530
- Rework Server-side Filter APIs by @mayuki in #552
- Move loggers to MagicOnion.Server.Diagnostics by @mayuki in #557
- Rework {Server,Client,Duplex}Streaming by @mayuki in #558
- Adopt to .NET 7 and drop support for .NET Core 3.1, .NET 5 on servers by @mayuki in #573
- Remove ChangeSerializer from ServiceContext by @mayuki in #580
- Drop MagicOnion.MSBuild.Tasks by @mayuki in #582
- Remove
UnaryResult()
andReturnNil()
helper methods by @mayuki in #589
Features
- Read and write directly to the buffer using IBufferWriter when calling Unary by @mayuki in #496
- Allow ValueTask as a return type of the hub method. by @mayuki in #583
- Introduce ClientFactoryProvider by @mayuki in #588
- Support for serialization using MemoryPack by @mayuki in #590
- Use ModuleInitializer for automatic registration on .NET 5+ by @mayuki in #578
- Non-Generic UnaryResult by @mayuki in #579
- Extensible message serialization by @mayuki in #577
Other Changes
Ver.4.5.2
Ver.4.5.1
What's Changed
Other Changes
- FIX: codegen system type fix by @gavar in #520
- Add support for known generic types to generator by @mayuki in #525
- Bump Newtonsoft.Json from 12.0.2 to 13.0.1 in /src/MagicOnion.Server.HttpGateway by @dependabot in #523
- Update README.md by @mayuki in #527
New Contributors
Full Changelog: 4.5.0...4.5.1
Ver.4.5.0
What's Changed
Breaking Changes
Reduce the maximum number of method parameters in #519
Limit the number of parameters allowed in a Unary/StreamingHub method for Blazor WebAssembly (AOT) to 15.
Other Changes
- Fix
using
when only Grpc.Net.Client is used on Unity in #518 - Annotate nullable properties not required in Swagger, fixes #456 by @AlexVallat in #515
New Contributors
- @AlexVallat made their first contribution in #515
Full Changelog: 4.4.1...4.5.0
Ver.4.4.1
What's Changed
Other Changes
- If a user leaves the room, another user joins the same room, and then the user who leaves the room disconnects, the shared data in the room will be deleted. by @taketoriokina in #494
- Update readme for Unity by @yucchiy in #511
New Contributors
- @taketoriokina made their first contribution in #494
- @yucchiy made their first contribution in #511
Full Changelog: 4.4.0...4.4.1
Ver.4.4.0
Breaking Changes
Remove MagicOnion.Server.Authentication in #483 #484
We will no longer provide and support MagicOnion.Server.Authentication (Preview package).
If your applicaiton requires authentication mechanism, this can be achieved on top of the standard authentication mechanism in ASP.NET Core.
See: Authentication and authorization in gRPC for ASP.NET Core
Features
- Add UnaryResult.FromResult(), UnaryResult.Nil in #463
- Make default(UnaryResult) awaitable in #466
- Target .NET 6 in #469 #470
- Introduce GenerateIfDirectiveAttribute in #493
Improvements
- Use RequestServices instead of a manually scoped ServiceProvider in #479
- Clarify the message when it fails to negotiate with the server in #480
- Pass attributes as metadata on binding gRPC method in #484
Other Changes
- Add code highlight hint to sample code for Filter by @bamchoh in #443
- feat: publish OpenTelemetry support to NuGet listed latest version. by @guitarrapc in #422
- MagicOnion.Unity: Grpc.Net.Client in #446 #447
- Symbols should not be cached across Compilation in #448
- Fix typos in README by @hankovich in #450
- Ignore PackageReference element if it does not have Include attribute in #454
- Update smple code "await foreach" by @NepPure in #468
- Ignore exception on disconnection by STREAM_RST in #475
- HttpGateway breaks if service uses explicit interface implementation feature by @bearpro in #473
- Ignore InvalidOperationException if the connection is completed in #478
- Fix warnings in #477
New Contributors
- @bamchoh made their first contribution in #443
- @hankovich made their first contribution in #450
- @NepPure made their first contribution in #468
- @bearpro made their first contribution in #473
Full Changelog: 4.3.1...4.4.0
Ver.4.3.1
Ver.4.3.0
Changes
Breaking changes
[Client] Use ChannelBase for channel abstraction #433
Use ChannelBase
(included in Grpc.Core.Api) for channel abstraction.
Remove overloads to receive IMagicOnionAwareGrpcChannel
, Channel
, GrpcChannel
from MagicOnionClient
and StreamingHubClient
.
MagicOnion now requires gRPC v1.27.0 (Grpc.Core.Api v2.27.0) or later.
You may need to remove following source codes from your Unity project.
- MagicOnionClient.CCore.cs
- MagicOnionClient.NetStandard.cs
- StreamingHubClient.CCore.cs
- StreamingHubClient.NetStandard.cs
API changes and deprecation
[Client.Unity] Make the method names of GrpcChannelx like the API of GrpcChannel #434
Because GrpcChannel has a method named ForAddress, GrpcChannelx follows it.
Following APIs are marked as deprecated:
GrpcChannelx.FromAddress(Uri)
GrpcChannelx.FromTarget(GrpcChannelTarget)
Use GrpcChannelx.ForAddress
or GrpcChannelx.ForTarget
instead.
Ver.4.2.0
New Features
Unity: Introduce gRPC channel management integration #414
Wraps gRPC channels and provides a mechanism to manage them with Unity's lifecycle.
This prevents your application and the Unity Editor from freezing by releasing channels and StreamingHub in one place.
The editor extension also provides the ability to display the communication status of channels.
NOTE: The data rate is calculated only for the message body of methods, and does not include Headers, Trailers, or Keep-alive pings.
New APIs
MagicOnion.GrpcChannelx
class
GrpcChannelx.FromTarget(GrpcChannelTarget)
methodGrpcChannelx.FromAddress(Uri)
method
MagicOnion.Unity.GrpcChannelProviderHost
class
GrpcChannelProviderHost.Initialize(IGrpcChannelProvider)
method
MagicOnion.Unity.IGrpcChannelProvider
interface
DefaultGrpcChannelProvider
classLoggingGrpcChannelProvider
class
Usages
1. Prepare to use GrpcChannelx
in your Unity project.
Before creating a channel in your application, you need to initialize the provider host to be managed.
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void OnRuntimeInitialize()
{
// Initialize gRPC channel provider when the application is loaded.
GrpcChannelProviderHost.Initialize(new DefaultGrpcChannelProvider(new []
{
// send keepalive ping every 5 second, default is 2 hours
new ChannelOption("grpc.keepalive_time_ms", 5000),
// keepalive ping time out after 5 seconds, default is 20 seconds
new ChannelOption("grpc.keepalive_timeout_ms", 5 * 1000),
}));
}
GrpcChannelProviderHost will be created as DontDestroyOnLoad and keeps existing while the application is running. DO NOT destory it.
2. Use GrpcChannelx.FromTarget
or GrpcChannelx.FromAddress
to create a channel.
Use GrpcChannelx.FromTarget
or GrpcChannelx.FromAddress
to create a channel instead of new Channel(...)
.
var channel = GrpcChannelx.FromTarget(new GrpcChannelTarget("localhost", 12345, ChannelCredentials.Insecure));
// or
var channel = GrpcChannelx.FromAddress(new Uri("http://localhost:12345"));
3. Use the channel instead of Grpc.Core.Channel
.
var channel = GrpcChannelx.FromAddress(new Uri("http://localhost:12345"));
var serviceClient = MagicOnionClient.Create<IGreeterService>(channel);
var hubClient = StreamingHubClient.ConnectAsync<IGreeterHub, IGreeterHubReceiver>(channel, this);
Extensions for Unity Editor (Editor Window & Inspector)
Improvements
- Improve StreamingHub's grouping writer #416
Fixes
- Fix handling of Generics for StreamingHub code generation #419