56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
|
|
using Nacos.AspNetCore.V2;
|
|
using Nacos.V2.DependencyInjection;
|
|
using Microservice.Common;
|
|
using Microservice.Common.Services;
|
|
|
|
namespace MicoService.Demo
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
#region Nacos
|
|
// 配置 Nacos 配置中心
|
|
builder.Host.UseNacosConfig("nacos");
|
|
builder.Services.AddNacosV2Config(builder.Configuration);
|
|
|
|
// 配置 Nacos 注册发现
|
|
builder.Services.AddNacosAspNet(builder.Configuration);
|
|
builder.Services.AddNacosV2Naming(builder.Configuration);
|
|
#endregion
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
builder.Services.AddOpenApi();
|
|
|
|
// 注册微服务通讯客户端
|
|
builder.Services.AddServiceClient();
|
|
|
|
// 注册用户服务
|
|
builder.Services.AddScoped<IUserService, UserService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|
|
}
|
|
}
|
|
}
|