Created
July 12, 2019 02:58
-
-
Save tocalai/537f8831e328ae1fa48c09394cf48c70 to your computer and use it in GitHub Desktop.
Class for start and initial Grpc service instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App | |
{ | |
private readonly Grpc.Core.Server _serverInstance; | |
public App(string host, int port, params ServerServiceDefinition[] services) | |
{ | |
_serverInstance = new Grpc.Core.Server | |
{ | |
Ports = | |
{ | |
new ServerPort(host, port, ServerCredentials.Insecure) | |
} | |
}; | |
InitialAndStartServices(services); | |
} | |
private void InitialAndStartServices(ServerServiceDefinition[] services) | |
{ | |
services.ToList().ForEach(srv => | |
{ | |
_serverInstance.Services.Add(srv); | |
}); | |
_serverInstance.Start(); | |
Console.WriteLine($"Server listening on host = {_serverInstance.Ports.First().Host}, port = {_serverInstance.Ports.First().Port}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment