Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework gRPC method binding logic #864

Merged
merged 29 commits into from
Oct 24, 2024
Merged

Rework gRPC method binding logic #864

merged 29 commits into from
Oct 24, 2024

Conversation

mayuki
Copy link
Member

@mayuki mayuki commented Oct 24, 2024

This PR re-implements internal gRPC method binding logics.

Before this PR, The service registration logic for Unary/StreamingHub was independent from Grpc.AspNetCore.Server framework. Now, the registration logic of MagicOnion is being re-implemented more tightly based on Grpc.AspNetCore.Server.

This allows more flexible configuration of the MagicOnion gRPC service endpoint. MagicOnion endpoints can be registered in multiple calls.

var builder = WebApplicationBuilder.CreateBuilder(args);
builder.Services.AddMagicOnion();

var app = builder.Build();

// Register all Unary/StreamingHub services from loaded assemblies.
// app.MapMagicOnionService();

// Consumers endpoints
app.MapMagicOnionService([typeof(GreeterService), typeof(ChatHub)]);

// Administration endpoints
app.MapMagicOnionService([typeof(AdministrationService)])
    .RequireHost("*:6000")
    .RequireAuthorization();

app.Run();

Breaking changes

Obsolete AddMagicOnion(Assembly[] searchAssemblies) and AddMagicOnion(IEnumerable<Type> searchTypes)

services.AddMagicOnion(Assembly[] searchAssemblies) and services.AddMagicOnion(IEnumerable<Type> searchTypes) no longer work. Use app.MapMagicOnionService instead.

// Before
var builder = WebApplicationBuilder.CreateBuilder(args);
builder.Services.AddMagicOnion([typeof(MyService), typeof(MyHub)]);

var app = builder.Build();
app.MapMagicOnionService();
app.Run();
// After
var builder = WebApplicationBuilder.CreateBuilder(args);
builder.Services.AddMagicOnion();

var app = builder.Build();
app.MapMagicOnionService([typeof(MyService), typeof(MyHub)]);
app.Run();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants