MapGrpcService non static alternative
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 836
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 7
Description
Hello,
I am migrating server from Grpc.Core to Grpc.AspNetCore.Server.
In Grpc.Core I was using:
```
Grpc.Core.Server server = new Grpc.Core.Server()
{
Services = { _instanceOfMyServiceImplementation.GetServiceDefinition() },
Ports =
{
new ServerPort("0.0.0.0", 5555, Grpc.Core.ServerCredentials.Insecure)
}
};
```
In my service was following registration method and handler as:
```
public ServerServiceDefinition GetServiceDefinition()
{
return ServerServiceDefinition.CreateBuilder()
.AddMethod(_duplexCommunicationMethod, DuplexCommunication).Build();
}
```
for binding incommning calls to specific nonstatic processing method and handler.
I am now migrating to Grpc.AspNetCore.Server. I would like to avoid static classes, methods if possible. I was able to create my service as singleton. But I am not able to register processing _duplexCommunicationMethod method and handler from my instanced service implementation. I would need endpoints.MapGrpcService alternative mapping from specific instance not from Type and using static methods. Something like this:
```
var instanceOfMyServiceImplementation =
var builder = Host.CreateDefaultBuilder().ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseKestrel();
webBuilder.ConfigureServices(services =>
{
services.AddSingleton(communicationService);
services.AddGrpc();
});
webBuilder.Configure((context, app) =>
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.BindGrpcService(instanceOfMyServiceImplementation.BindService());
});
});
});
```
with BindService like this:
```
public ServiceBinderBase BindService ()
{
ServiceBinderBase sbb = new ServiceBinderBase();
sbb.AddMethod(_duplexCommunicationMethod, DuplexCommunication);
return sbb;
}
```
Is it possible? Thanks
Contributor guide
Research direction
Start with the ASP.NET Core gRPC endpoint entry point, endpoints.MapGrpcService, and compare it with the Grpc.Core GetServiceDefinition and BindService examples shown in the issue. Determine whether instance-based binding from an external DI container is supported; done means documenting a supported registration path or clearly recording that this mapping is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100