Releases: Cysharp/MagicOnion
6.0.1
6.0.0
Highlights
MagicOnion.Client.SourceGenerator in #688
This release introduces a source generator for platform that require pre-generated client code (e.g. Unity, NativeAOT, MAUI ...).
The source generator also replaces MagicOnion.Generator (moc).
MagicOnion.Client.SourceGenerator is shipped with MagicOnion.Client package. This means that you no longer need to the install generator tool (moc) and setup additional build steps.
Supported development environments
- Unity 2021.3.0f1 or later
- .NET 6 or later
- Visual Studio 2022 version 17.2 or later
- Rider 2023.1 or later
Usage
Define a partial class with any name of your choosing within the application. Mark it with the MagicOnionClientGeneration attribute, and specify any service type found within the assembly where you want to search for the service interface.
For example, if the MyApp.Shared assembly contains MyApp.Shared.Services.IGreeterService and MyApp.Shared.Hubs.IChatHub, specify one of them.
using MagicOnion.Client;
[MagicOnionClientGeneration(typeof(MyApp.Shared.Services.IGreeterService))]
partial class MagicOnionGeneratedClientInitializer {}Next, configure MessagePack to use the generated MessagePack Resolver. This is the same as when using the legacy MagicOnion.Generator.
#if UNITY_2019_4_OR_NEWER
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.BeforeSceneLoad)]
#elif NET5_0_OR_GREATER
[System.Runtime.CompilerServices.ModuleInitializer]
#endif
static void RegisterResolvers()
{
StaticCompositeResolver.Instance.Register(
// Add: Use MessagePack formatter resolver generated by the source generator.
MagicOnionGeneratedClientInitializer.Resolver,
MessagePack.Resolvers.GeneratedResolver.Instance,
BuiltinResolver.Instance,
PrimitiveObjectResolver.Instance
);
MessagePackSerializer.DefaultOptions = MessagePackSerializer.DefaultOptions
.WithResolver(StaticCompositeResolver.Instance);
}Source generation options
You can specify options in the named constructor of the attribute.
DisableAutoRegistration: Sets whether to disable automatically callingRegisterduring start-up. (Automatic registration requires .NET 5+ or Unity)MessagePackFormatterNamespace: Sets the namespace of pre-generated MessagePackFormatters. The default value isMessagePack.Formatters.Serializer: Sets the serializer used for message serialization. The default value isGenerateSerializerType.MessagePack.
Breaking changes
MagicOnion.Generator (moc) has been removed. The legacy generator is no longer supported.
Warning
While there is currently compatibility between MagicOnion.Client and MagicOnion.Generator (moc), there is no guarantee that this will be maintained.
Introduce ServiceContext.SetRawBytesResponse in #677
This PR introduces ServiceContext.SetRawBytesResponse method.
This method allows you to set raw byte sequences as a response. This makes it possible to send a cached response body without serialization.
public override async ValueTask Invoke(ServiceContext context, Func<ServiceContext, ValueTask> next)
{
if (ResponseBytesCache.TryGetValue(context.CallContext.Method, out var cachedBytes))
{
context.SetRawBytesResponse(cachedBytes);
return;
}
await next(context);
ResponseBytesCache[context.CallContext.Method] = MessagePackSerializer.Serialize(context.Result);
}Note
The raw byte sequence must be serialized as a MessagePack (or custom serialization) format. MagicOnion will write a byte requence directly into the response buffer.
Add StreamingHub metrics in #716
This release introduces metrics related to StreamingHub using System.Diagnostics.Metrics.
Meter: MagicOnion.Server
| Metric | Unit | Tags |
|---|---|---|
| magiconion.server.streaminghub.connections | {connection} |
rpc.system, rpc.service |
| magiconion.server.streaminghub.method_duration | ms |
rpc.system, rpc.service, rpc.method |
| magiconion.server.streaminghub.method_completed | {request} |
rpc.system, rpc.service, rpc.method, magiconion.streaminghub.is_error |
| magiconion.server.streaminghub.exceptions | {exception} |
rpc.system, rpc.service, rpc.method, error.type |
Tags
| Tag name | Value |
|---|---|
| rpc.system | magiconion |
| rpc.service | StreamingHub interface name (e.g. IGreeterService) |
| rpc.method | StreamingHub method name (e.g. HelloAsync) |
| magiconion.streaminghub.is_error | Whether a StreamingHub method call succeeded or failed. (e.g. true or false) |
| error.type | Thrown exception type (e.g. System.InvalidOperationException) |
Breaking Changes
Use Grpc.Net.Client by default on Unity in #704
This release changes the default gRPC library in Unity to grpc-dotnet.
From this release, the recommended gRPC library combination is YetAnotherHttpHandler and grpc-dotnet.
However, at this time, we are still supporting C-core. If you continue to use the C-core gRPC library, please define USE_GRPC_CCORE in "Scripting Define Symbols". We recommend transitioning as there is the possibility of removing support in the future.
refs: #661
Other Breaking Changes
- Switch to ILogger-based logging by @mayuki in #683
- Remove MagicOnion.Server.OpenTelemetry by @mayuki in #692
- Cleanup MagicOnion.Shared project by @mayuki in #699
- Remove GenerateDefineDebugAttribute and GenerateIfDirectiveAttribute by @mayuki in #701
- Reorganize internal shared code dependency by @mayuki in #707
- Move DynamicClientFactoryProviders to DynamicClient by @mayuki in #712
- Remove UniTask support by @mayuki in #729
What's Changes
Features
- Add MagicOnionClient.Create overload by @mayuki in #684
- MagicOnion.Client targets C# 9 and enable nullable annotations by @mayuki in #698
- Adopt to .NET 8 by @mayuki in #730
Other Changes
- Run continuation of hub method synchronously on Unity WebGL by @mayuki in #659
- Replace Moq with NSubstitute by @mayuki in #672
- Fix an incorrect root when a project references a shared project. by @mayuki in #674
- Make to accept a factory for GrpcChannelOptions by @mayuki in #678
- Fix code generation for formatter of Enum nested in a class by @mayuki in #679
- Make marker response bytes a constant by @mayuki in #681
- Refactor StreamingHub by @mayuki in #682
- Update dependencies by @mayuki in #697
- Fix code generation for MemoryPack by @mayuki in #700
- Revert "Merge pull request #701 from Cysharp/feature/RemoveGenerateAttribute by @mayuki in #706
- Fix check for ignored assembly names by @mayuki in #711
- Update action.yaml to use Cysharp/Actions/setup-dotnet by @guitarrapc in #715
- Restore MethodCollector tests by @mayuki in #721
- Add support for interface inheritance on StreamingHub by @mayuki in #722
- Fix error when a source code contains alias-qualified attribute names by @mayuki in #727
Full Changelog: 5.1.8...6.0.0
Ver.5.1.8
What's Changed
Other Changes
- Fix invalid code generation for ValueTuple by @mayuki in #651
- Use MessagePackReader/Writer to read extra message in error responses by @mayuki in #653 (Thanks @hegi25; #650)
- Fix unable to handle an interface with the same name by @mayuki in #654
Full Changelog: 5.1.7...5.1.8
Ver.5.1.7
What's Changed
- Run continuations of hub method calls asynchronously. by @mayuki in #642
- fix DeclaringType code generate issue #643 by @sableangle in #644
New Contributors
- @sableangle made their first contribution in #644
Full Changelog: 5.1.6...5.1.7
Ver.5.1.6
What's Changed
Other Changes
- Add MagicOnionClient.Create overload by @mayuki in #640
- Fix code generation for Unity with .NET Framework by @g2-nagasaki-shota in #636
New Contributors
- @g2-nagasaki-shota made their first contribution in #636
Full Changelog: 5.1.5...5.1.6
Ver.5.1.5
Ver.5.1.4
Ver.5.1.3
What's Changed
Full Changelog: 5.1.2...5.1.3
Ver.5.1.2
Ver.5.1.0
⚠ Important: Fixes handling of null values in request/response. in #610
Version 5.0.x series cannot handle null passed in the request and response.
If the request/response is value type (struct) or if the method takes more than one argument, it is not affected, but we strongly recommend upgrading.
Breaking changes
ResponseContext<T> class is now abstract and ResponseContext<T>.Create method is used instead of a constructor.
What's Changed
Bug Fixes
- Fix method signature of MemoryPackFormatter for Unity by @mayuki in #611
- Remove DynamicClientBuilder when targeting .NET Standard on Unity by @mayuki in #606
Other Changes
New Contributors
Full Changelog: 5.0.2...5.1.0