| | | 1 | | using Intentum.Core.Behavior; |
| | | 2 | | using Microsoft.AspNetCore.Builder; |
| | | 3 | | using Microsoft.Extensions.DependencyInjection; |
| | | 4 | | |
| | | 5 | | namespace Intentum.AspNetCore; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Extension methods for integrating Intentum with ASP.NET Core. |
| | | 9 | | /// </summary> |
| | | 10 | | public static class IntentumAspNetCoreExtensions |
| | | 11 | | { |
| | 0 | 12 | | private static readonly string[] HealthCheckTagsEmbedding = ["intentum", "embedding"]; |
| | 0 | 13 | | private static readonly string[] HealthCheckTagsPolicy = ["intentum", "policy"]; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Adds Intentum services to the service collection. |
| | | 17 | | /// </summary> |
| | | 18 | | public static IServiceCollection AddIntentum(this IServiceCollection services) |
| | 0 | 19 | | { |
| | 0 | 20 | | services.AddSingleton<BehaviorSpace>(); |
| | 0 | 21 | | return services; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Adds Intentum services with a custom BehaviorSpace instance. |
| | | 26 | | /// </summary> |
| | | 27 | | public static IServiceCollection AddIntentum(this IServiceCollection services, BehaviorSpace behaviorSpace) |
| | 0 | 28 | | { |
| | 0 | 29 | | services.AddSingleton(behaviorSpace); |
| | 0 | 30 | | return services; |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Uses Intentum behavior observation middleware. |
| | | 35 | | /// </summary> |
| | | 36 | | public static IApplicationBuilder UseIntentumBehaviorObservation( |
| | | 37 | | this IApplicationBuilder app, |
| | | 38 | | BehaviorObservationOptions? options = null) |
| | 0 | 39 | | { |
| | 0 | 40 | | var behaviorSpace = app.ApplicationServices.GetRequiredService<BehaviorSpace>(); |
| | 0 | 41 | | return app.UseMiddleware<BehaviorObservationMiddleware>(behaviorSpace, options); |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Adds Intentum health checks. |
| | | 46 | | /// </summary> |
| | | 47 | | public static IHealthChecksBuilder AddIntentumHealthChecks( |
| | | 48 | | this IServiceCollection services) |
| | 0 | 49 | | { |
| | 0 | 50 | | services.AddSingleton<HealthChecks.EmbeddingProviderHealthCheck>(); |
| | 0 | 51 | | services.AddSingleton<HealthChecks.PolicyEngineHealthCheck>(); |
| | | 52 | | |
| | 0 | 53 | | return services.AddHealthChecks() |
| | 0 | 54 | | .AddCheck<HealthChecks.EmbeddingProviderHealthCheck>( |
| | 0 | 55 | | "embedding-provider", |
| | 0 | 56 | | tags: HealthCheckTagsEmbedding) |
| | 0 | 57 | | .AddCheck<HealthChecks.PolicyEngineHealthCheck>( |
| | 0 | 58 | | "policy-engine", |
| | 0 | 59 | | tags: HealthCheckTagsPolicy); |
| | 0 | 60 | | } |
| | | 61 | | } |