2024-10-30 11:53:37 -07:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// AgentWorkerHostingExtensions.cs
|
|
|
|
|
2024-10-02 11:42:27 -07:00
|
|
|
using System.Diagnostics;
|
2024-07-25 00:06:06 -07:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-06-28 08:03:42 -07:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-07-25 00:06:06 -07:00
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
2024-10-02 11:42:27 -07:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2024-06-28 08:03:42 -07:00
|
|
|
|
2024-11-12 11:04:59 -08:00
|
|
|
namespace Microsoft.AutoGen.Agents;
|
2024-06-28 08:03:42 -07:00
|
|
|
|
|
|
|
public static class AgentWorkerHostingExtensions
|
|
|
|
{
|
2024-11-18 13:32:49 -08:00
|
|
|
public static IHostApplicationBuilder AddAgentService(this IHostApplicationBuilder builder, bool local = false, bool useGrpc = true)
|
2024-06-28 08:03:42 -07:00
|
|
|
{
|
2024-11-18 13:32:49 -08:00
|
|
|
builder.AddOrleans(local);
|
2024-11-12 11:04:59 -08:00
|
|
|
|
2024-07-25 00:06:06 -07:00
|
|
|
builder.Services.TryAddSingleton(DistributedContextPropagator.Current);
|
2024-11-12 11:04:59 -08:00
|
|
|
|
|
|
|
if (useGrpc)
|
|
|
|
{
|
|
|
|
builder.Services.AddGrpc();
|
|
|
|
builder.Services.AddSingleton<GrpcGateway>();
|
|
|
|
builder.Services.AddSingleton<IHostedService>(sp => (IHostedService)sp.GetRequiredService<GrpcGateway>());
|
|
|
|
}
|
2024-06-28 08:03:42 -07:00
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2024-11-18 13:32:49 -08:00
|
|
|
public static IHostApplicationBuilder AddLocalAgentService(this IHostApplicationBuilder builder, bool useGrpc = true)
|
2024-10-08 10:02:48 -07:00
|
|
|
{
|
2024-11-19 11:00:48 -08:00
|
|
|
return builder.AddAgentService(local: false, useGrpc);
|
2024-10-08 10:02:48 -07:00
|
|
|
}
|
2024-11-18 13:32:49 -08:00
|
|
|
|
2024-11-12 11:04:59 -08:00
|
|
|
public static WebApplication MapAgentService(this WebApplication app, bool local = false, bool useGrpc = true)
|
2024-06-28 08:03:42 -07:00
|
|
|
{
|
2024-11-12 11:04:59 -08:00
|
|
|
if (useGrpc) { app.MapGrpcService<GrpcGatewayService>(); }
|
2024-06-28 08:03:42 -07:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
}
|