47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Register XAiMcpHandler Service ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
public static void AddXAiMcpHandler(
|
|
this IServiceCollection source
|
|
)
|
|
{
|
|
//
|
|
// Register MCP User Context ...
|
|
source.AddScoped<IXAiMcpUserContext, XAiMcpUserContext>();
|
|
|
|
//
|
|
// 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<IXAiMcpHandler, XAiMcpHandler>();
|
|
}
|
|
}
|
|
} |