2024-07-25 00:06:06 -07:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-06-28 08:03:42 -07:00
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Orleans.Serialization;
|
2024-07-25 00:06:06 -07:00
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
using System.Diagnostics;
|
2024-06-28 08:03:42 -07:00
|
|
|
|
2024-09-18 11:57:51 -07:00
|
|
|
namespace Microsoft.AutoGen.Agents.Worker;
|
2024-06-28 08:03:42 -07:00
|
|
|
|
|
|
|
public static class AgentWorkerHostingExtensions
|
|
|
|
{
|
|
|
|
public static IHostApplicationBuilder AddAgentService(this IHostApplicationBuilder builder)
|
|
|
|
{
|
|
|
|
builder.Services.AddGrpc();
|
|
|
|
builder.Services.AddSerializer(serializer => serializer.AddProtobufSerializer());
|
|
|
|
|
|
|
|
// Ensure Orleans is added before the hosted service to guarantee that it starts first.
|
|
|
|
builder.UseOrleans();
|
2024-07-25 00:06:06 -07:00
|
|
|
builder.Services.TryAddSingleton(DistributedContextPropagator.Current);
|
2024-06-28 08:03:42 -07:00
|
|
|
builder.Services.AddSingleton<WorkerGateway>();
|
|
|
|
builder.Services.AddSingleton<IHostedService>(sp => sp.GetRequiredService<WorkerGateway>());
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WebApplication MapAgentService(this WebApplication app)
|
|
|
|
{
|
|
|
|
app.MapGrpcService<WorkerGatewayService>();
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
}
|