2022-10-21 09:55:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Server.Implementations.Extensions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extensions for the <see cref="IServiceCollection"/> interface.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class ServiceCollectionExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the <see cref="IDbContextFactory{TContext}"/> interface to the service collection with second level caching enabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceCollection">An instance of the <see cref="IServiceCollection"/> interface.</param>
|
|
|
|
|
/// <returns>The updated service collection.</returns>
|
2024-06-01 00:01:54 +00:00
|
|
|
|
public static IServiceCollection AddJellyfinDbContext(this IServiceCollection serviceCollection)
|
2022-10-21 09:55:32 +00:00
|
|
|
|
{
|
2023-01-16 17:14:44 +00:00
|
|
|
|
serviceCollection.AddPooledDbContextFactory<JellyfinDbContext>((serviceProvider, opt) =>
|
2022-10-21 09:55:32 +00:00
|
|
|
|
{
|
|
|
|
|
var applicationPaths = serviceProvider.GetRequiredService<IApplicationPaths>();
|
2024-06-01 00:01:54 +00:00
|
|
|
|
opt.UseSqlite($"Filename={Path.Combine(applicationPaths.DataPath, "jellyfin.db")}");
|
2022-10-21 09:55:32 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return serviceCollection;
|
|
|
|
|
}
|
|
|
|
|
}
|