Skip to content

Ver.5.0.0

Compare
Choose a tag to compare
@github-actions github-actions released this 28 Dec 02:42

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 under MagicOnion.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.

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 from IMagicOnionLogger
  • Remove MagicOnionLogToLoggerWithDataDump, MagicOnionLogToLoggerWithNamedDataDump
  • Change the signature of SetRawRequest / GetRawRequest from byte[] to object

Rework {Server,Client,Duplex}Streaming #558

Change {Server,Client,Duplex}Streaming message processing on the server to IBufferWriter-based.

Breaking changes

  • Remove data parameter from IMagicOnionLogger.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 and ResponseMutator 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.
  • 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 of MessagePackSerializerOptions.
  • Server: Use MagicOnionOptions.MessageSerializer instead of MagicOnionOptions.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() and ReturnNil() 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

  • Enable Source Link by @mayuki in #498
  • Treats the request type of parameter-less methods as Nil by @mayuki in #499
  • Fixed incorrect IL outputs for parameter-less ServerStreaming. by @mayuki in #503
  • Fix ReturnStatusException returns incorrect response status code by @mayuki in #508
  • Add verbose logging option to Generator by @mayuki in #531
  • Update ConsoleAppFramework by @mayuki in #533
  • Introduce SimpleBenchmarkApp by @mayuki in #540
  • Add benchmark reporting feature by @mayuki in #543
  • Add UnaryComplex by @mayuki in #545
  • Delete Nuget.config by @mayuki in #546
  • Move unit test codes by @mayuki in #553
  • Cleanup codes by @mayuki in #554
  • Excludes non-public services and hubs when collecting types. by @mayuki in #555
  • Excludes generic definitions when collecting types from assembly by @mayuki in #556
  • Respects Ignore attribute when collecting methods and interfaces by @mayuki in #570
  • Allow interface to target of Ignore attribute by @mayuki in #571
  • Allow to call methods declared in base interfaces by @Alezy80 in #567
  • Support ImplicitUsings/GlobalUsings by @mayuki in #572
  • Add support for Tuple/ValueTuple by @mayuki in #575
  • Add unit tests for generated clients by @mayuki in #576
  • Fix special marshaller for parameter-less method by @mayuki in #581
  • Fix With* methods to work properly by @mayuki in #585
  • Rename IMagicOnionMessageSerializer -> IMagicOnionSerializer by @mayuki in #586
  • Fix StreamingHub dynamic client incorrectly handling ValueTask return type. by @mayuki in #587
  • Fix accidental deletion of counter key using Redis by @mayuki in #591
  • MagicOnion 5.0 by @mayuki in #497

New Contributors

Full Changelog: 4.5.2...5.0.0