2
0

ServiceCollectionExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.IO;
  3. using MediaBrowser.Common.Configuration;
  4. using Microsoft.EntityFrameworkCore;
  5. using Microsoft.Extensions.DependencyInjection;
  6. namespace Jellyfin.Server.Implementations.Extensions;
  7. /// <summary>
  8. /// Extensions for the <see cref="IServiceCollection"/> interface.
  9. /// </summary>
  10. public static class ServiceCollectionExtensions
  11. {
  12. /// <summary>
  13. /// Adds the <see cref="IDbContextFactory{TContext}"/> interface to the service collection with second level caching enabled.
  14. /// </summary>
  15. /// <param name="serviceCollection">An instance of the <see cref="IServiceCollection"/> interface.</param>
  16. /// <returns>The updated service collection.</returns>
  17. public static IServiceCollection AddJellyfinDbContext(this IServiceCollection serviceCollection)
  18. {
  19. serviceCollection.AddPooledDbContextFactory<JellyfinDbContext>((serviceProvider, opt) =>
  20. {
  21. var applicationPaths = serviceProvider.GetRequiredService<IApplicationPaths>();
  22. opt.UseSqlite($"Filename={Path.Combine(applicationPaths.DataPath, "jellyfin.db")}");
  23. });
  24. return serviceCollection;
  25. }
  26. }