Skip to content

6.0.0

Compare
Choose a tag to compare
@github-actions github-actions released this 11 Jan 10:26
· 0 commits to ae1a0b5dab4496c137591d6530d8b9f2c8f220d3 since this release

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 calling Register during start-up. (Automatic registration requires .NET 5+ or Unity)
  • MessagePackFormatterNamespace: Sets the namespace of pre-generated MessagePackFormatters. The default value is MessagePack.Formatters.
  • Serializer: Sets the serializer used for message serialization. The default value is GenerateSerializerType.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