| | | 1 | | using Elsa.AI.Abstractions.Contracts; |
| | | 2 | | using Elsa.AI.Persistence.EFCore; |
| | | 3 | | using Elsa.AI.Persistence.EFCore.Services; |
| | | 4 | | using Elsa.AI.Persistence.EFCore.Stores; |
| | | 5 | | using Microsoft.EntityFrameworkCore; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 8 | | using Microsoft.Extensions.Hosting; |
| | | 9 | | |
| | | 10 | | // ReSharper disable once CheckNamespace |
| | | 11 | | namespace Elsa.Extensions; |
| | | 12 | | |
| | | 13 | | public static class ServiceCollectionExtensions |
| | | 14 | | { |
| | | 15 | | public static IServiceCollection AddAIPersistenceStores(this IServiceCollection services, Action<DbContextOptionsBui |
| | | 16 | | { |
| | 29 | 17 | | if (!services.Any(x => x.ServiceType == typeof(DbContextOptions<AIDbContext>))) |
| | | 18 | | { |
| | 4 | 19 | | if (configureDbContext == null) |
| | 1 | 20 | | throw new InvalidOperationException($"Register {nameof(AIDbContext)} with configured {nameof(DbContextOp |
| | | 21 | | else |
| | 3 | 22 | | services.AddDbContext<AIDbContext>(configureDbContext); |
| | | 23 | | } |
| | | 24 | | |
| | 4 | 25 | | services.TryAddScoped<AIDbContext>(); |
| | | 26 | | |
| | 4 | 27 | | services.Replace(ServiceDescriptor.Scoped<IAIConversationStore, EFCoreAIConversationStore>()); |
| | 4 | 28 | | services.Replace(ServiceDescriptor.Scoped<IAIProposalStore, EFCoreAIProposalStore>()); |
| | 4 | 29 | | services.TryAddEnumerable(ServiceDescriptor.Scoped<IAIAuditEventHandler, EFCoreAIAuditSink>()); |
| | 4 | 30 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, EFCoreAIConversationCleanupService>()); |
| | | 31 | | |
| | 4 | 32 | | return services; |
| | | 33 | | } |
| | | 34 | | } |