80 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System.Text.Json;
 | 
						|
using System.Text.Json.Serialization;
 | 
						|
using DysonNetwork.Insight.Thought;
 | 
						|
using DysonNetwork.Shared.Cache;
 | 
						|
using Microsoft.SemanticKernel;
 | 
						|
using NodaTime;
 | 
						|
using NodaTime.Serialization.SystemTextJson;
 | 
						|
 | 
						|
namespace DysonNetwork.Insight.Startup;
 | 
						|
 | 
						|
public static class ServiceCollectionExtensions
 | 
						|
{
 | 
						|
    public static IServiceCollection AddAppServices(this IServiceCollection services)
 | 
						|
    {
 | 
						|
        services.AddDbContext<AppDatabase>();
 | 
						|
        services.AddSingleton<IClock>(SystemClock.Instance);
 | 
						|
        services.AddHttpContextAccessor();
 | 
						|
        services.AddSingleton<ICacheService, CacheServiceRedis>();
 | 
						|
 | 
						|
        services.AddHttpClient();
 | 
						|
 | 
						|
        // Register gRPC services
 | 
						|
        services.AddGrpc(options =>
 | 
						|
        {
 | 
						|
            options.EnableDetailedErrors = true; // Will be adjusted in Program.cs
 | 
						|
            options.MaxReceiveMessageSize = 16 * 1024 * 1024; // 16MB
 | 
						|
            options.MaxSendMessageSize = 16 * 1024 * 1024; // 16MB
 | 
						|
        });
 | 
						|
        services.AddGrpcReflection();
 | 
						|
 | 
						|
        // Register gRPC services
 | 
						|
 | 
						|
        // Register OIDC services
 | 
						|
        services.AddControllers().AddJsonOptions(options =>
 | 
						|
        {
 | 
						|
            options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals;
 | 
						|
            options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
 | 
						|
            options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.SnakeCaseLower;
 | 
						|
 | 
						|
            options.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
 | 
						|
        });
 | 
						|
 | 
						|
        return services;
 | 
						|
    }
 | 
						|
 | 
						|
    public static IServiceCollection AddAppAuthentication(this IServiceCollection services)
 | 
						|
    {
 | 
						|
        services.AddAuthorization();
 | 
						|
        return services;
 | 
						|
    }
 | 
						|
 | 
						|
    public static IServiceCollection AddAppFlushHandlers(this IServiceCollection services)
 | 
						|
    {
 | 
						|
        services.AddSingleton<FlushBufferService>();
 | 
						|
 | 
						|
        return services;
 | 
						|
    }
 | 
						|
 | 
						|
    public static IServiceCollection AddAppBusinessServices(this IServiceCollection services)
 | 
						|
    {
 | 
						|
        return services;
 | 
						|
    }
 | 
						|
 | 
						|
    public static IServiceCollection AddThinkingServices(this IServiceCollection services, IConfiguration configuration)
 | 
						|
    {
 | 
						|
        services.AddSingleton<ThoughtProvider>();
 | 
						|
        services.AddScoped<ThoughtService>();
 | 
						|
 | 
						|
        // Add gRPC clients for ThoughtService
 | 
						|
        services.AddGrpcClient<Shared.Proto.PaymentService.PaymentServiceClient>(o => o.Address = new Uri("https://_grpc.pass"))
 | 
						|
            .ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler()
 | 
						|
                { ServerCertificateCustomValidationCallback = (_, _, _, _) => true });
 | 
						|
        services.AddGrpcClient<Shared.Proto.WalletService.WalletServiceClient>(o => o.Address = new Uri("https://_grpc.pass"))
 | 
						|
            .ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler()
 | 
						|
                { ServerCertificateCustomValidationCallback = (_, _, _, _) => true });
 | 
						|
 | 
						|
        return services;
 | 
						|
    }
 | 
						|
}
 |