Open SAgiKPJH opened 5 days ago
// Program.cs
Console.WriteLine("Hello, World!");
{
}
// Program.cs
using DockerDIService.PrintService;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var build = new ConfigurationBuilder();
build.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true) .AddEnvironmentVariables();
var host = Host.CreateDefaultBuilder() .ConfigureServices((context, services) => { services.AddTransient<IPrint, PrintConsole>(); }) .Build();
var printService = host.Services.GetRequiredService
```cs
public interface IPrint
{
public void Print(string message);
}
public class PrintConsole : IPrint
{
public void Print(string message) =>
Console.WriteLine(message);
}
Protos
syntax = "proto3";
option csharp_namespace = "DockerGrpcServer.Protos";
service Hello { rpc Hello (HelloRequest) return (HelloReply); }
message HelloRequest { string message = 1; }
message HelloReply { string reply = 1; }
using DockerGrpcServer.Protos;
using Grpc.Core;
namespace DockerGrpcServer.Services;
public class HelloService : Hello.HelloBase { public HelloService() { }
public override async Task<HelloReply> Hello(HelloRequest request, ServerCallContext context)
{
await Task.CompletedTask;
return new HelloReply() { Reply = "Hello World!" };
}
}
```cs
using DockerGrpcServer.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddGrpc();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapGrpcService<HelloService>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run();
진행 과정
기초
서비스 구성
서비스 구현
모니터링 구현