2020-05-02 15:32:22 -07:00
|
|
|
using System;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
namespace Jellyfin.Server.Implementations
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Factory class for generating new <see cref="JellyfinDb"/> instances.
|
|
|
|
/// </summary>
|
|
|
|
public class JellyfinDbProvider
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="JellyfinDbProvider"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="serviceProvider">The application's service provider.</param>
|
|
|
|
public JellyfinDbProvider(IServiceProvider serviceProvider)
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
2020-05-15 14:24:01 -07:00
|
|
|
serviceProvider.GetRequiredService<JellyfinDb>().Database.Migrate();
|
2020-05-02 15:32:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="JellyfinDb"/> context.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The newly created context.</returns>
|
|
|
|
public JellyfinDb CreateContext()
|
|
|
|
{
|
2020-05-14 14:13:45 -07:00
|
|
|
return _serviceProvider.GetRequiredService<JellyfinDb>();
|
2020-05-02 15:32:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|