using System;
using System.Linq;
using System.Reflection;
using xAiService.Services;
using xAiService.Interfaces;
using Microsoft.Extensions.DependencyInjection;
namespace xAiService.Extensions
{
public static class DIExtensions
{
///
/// Register XAiMcpHandler Service ...
///
///
public static void AddXAiMcpHandler(
this IServiceCollection source
)
{
//
// Register MCP User Context ...
source.AddScoped();
//
// Register MCP Tool Scanner ...
source.AddSingleton(sp =>
{
//
// Scan All Exists Assemblies ...
var asms = AppDomain.CurrentDomain
.GetAssemblies()
.Where(a => !a.IsDynamic &&
a.GetName().Name != null &&
a.GetName().Name!.StartsWith("xAi", StringComparison.OrdinalIgnoreCase))
.Append(Assembly.GetEntryAssembly()!)
.ToArray();
//
return new XAiMcpToolScanner(asms);
});
//
// 2) Register MCP Handler ...
source.AddScoped();
}
}
}