diff --git a/Kyoo.Common/Controllers/IPlugin.cs b/Kyoo.Common/Controllers/IPlugin.cs
index a6949083..e4a058af 100644
--- a/Kyoo.Common/Controllers/IPlugin.cs
+++ b/Kyoo.Common/Controllers/IPlugin.cs
@@ -1,8 +1,14 @@
+using JetBrains.Annotations;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.Configuration;
+using Unity;
+
namespace Kyoo.Controllers
{
///
/// A common interface used to discord plugins
///
+ [UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IPlugin
{
///
@@ -19,21 +25,35 @@ namespace Kyoo.Controllers
/// The description of this plugin. This will be displayed on the "installed plugins" page.
///
string Description { get; }
-
-
+
///
- /// A configure method that will be runned on plugin's startup.
+ /// A list of services that are provided by this service. This allow other plugins to declare dependencies.
///
///
- /// You can have use any services as parameter, they will be injected from the service provider
- /// You can add managed types or any type you like using the IUnityContainer like so:
- ///
- /// public static void Configure(IUnityContainer services)
- /// {
- /// services.AddTask<MyTask>()
- /// }
- ///
+ /// The format should be the name of the interface ':' and the name of the implementation.
+ /// For a plugins that provide a new service named IService with a default implementation named Koala, that would
+ /// be "IService:Koala".
///
- static void Configure() { }
+ string[] Provides { get; }
+
+ ///
+ /// A list of services that are required by this service.
+ /// The Core will warn the user that this plugin can't be loaded if a required service is not found.
+ ///
+ ///
+ /// This is the same format as but you may leave a blank implementation's name if you don't need a special one.
+ /// For example, if you need a service named IService but you don't care what implementation it will be, you can use
+ /// "IService:"
+ ///
+ string[] Requires { get; }
+
+ ///
+ /// A configure method that will be run on plugin's startup.
+ ///
+ /// A unity container to register new services.
+ /// The configuration, if you need values at config time (database connection strings...)
+ /// The Asp.Net application builder. On most case it is not needed but you can use it to add asp net functionalities.
+ /// True if the app should run in debug mode.
+ void Configure(IUnityContainer container, IConfiguration config, IApplicationBuilder app, bool debugMode);
}
}
\ No newline at end of file
diff --git a/Kyoo.Common/Controllers/ITaskManager.cs b/Kyoo.Common/Controllers/ITaskManager.cs
index 7f3b6013..1197f049 100644
--- a/Kyoo.Common/Controllers/ITaskManager.cs
+++ b/Kyoo.Common/Controllers/ITaskManager.cs
@@ -18,7 +18,7 @@ namespace Kyoo.Controllers
/// A list of arguments to pass to the task. An automatic conversion will be made if arguments to not fit.
/// If the number of arguments is invalid or if an argument can't be converted.
/// The task could not be found.
- void StartTask(string taskSlug, Dictionary arguments);
+ void StartTask(string taskSlug, Dictionary arguments = null);
///
/// Get all currently running tasks
diff --git a/Kyoo.Common/Kyoo.Common.csproj b/Kyoo.Common/Kyoo.Common.csproj
index 3f4fdbba..b9417da8 100644
--- a/Kyoo.Common/Kyoo.Common.csproj
+++ b/Kyoo.Common/Kyoo.Common.csproj
@@ -23,6 +23,7 @@
+
diff --git a/Kyoo.Common/Module.cs b/Kyoo.Common/Module.cs
index 41b5859c..639e7c2a 100644
--- a/Kyoo.Common/Module.cs
+++ b/Kyoo.Common/Module.cs
@@ -1,3 +1,4 @@
+using System;
using Kyoo.Controllers;
using Unity;
@@ -11,14 +12,14 @@ namespace Kyoo
///
/// Register a new task to the container.
///
- /// The container
+ /// The container
/// The type of the task
/// The initial container.
- public static IUnityContainer AddTask(this IUnityContainer services)
+ public static IUnityContainer RegisterTask(this IUnityContainer container)
where T : class, ITask
{
- services.RegisterSingleton();
- return services;
+ container.RegisterType();
+ return container;
}
}
}
\ No newline at end of file
diff --git a/Kyoo.Postgresql/Kyoo.Postgresql.csproj b/Kyoo.Postgresql/Kyoo.Postgresql.csproj
new file mode 100644
index 00000000..e0089c22
--- /dev/null
+++ b/Kyoo.Postgresql/Kyoo.Postgresql.csproj
@@ -0,0 +1,18 @@
+
+
+
+ net5.0
+
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
diff --git a/Kyoo.Postgresql/PostgresContext.cs b/Kyoo.Postgresql/PostgresContext.cs
new file mode 100644
index 00000000..9d20cf53
--- /dev/null
+++ b/Kyoo.Postgresql/PostgresContext.cs
@@ -0,0 +1,76 @@
+using System;
+using Kyoo.Models;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
+using Npgsql;
+
+namespace Kyoo.Postgresql
+{
+ ///
+ /// A postgresql implementation of .
+ ///
+ public class PostgresContext : DatabaseContext
+ {
+ ///
+ /// The connection string to use.
+ ///
+ private readonly string _connection;
+
+ ///
+ /// Is this instance in debug mode?
+ ///
+ private readonly bool _debugMode;
+
+ ///
+ /// A basic constructor that set default values (query tracker behaviors, mapping enums...)
+ ///
+ public PostgresContext()
+ {
+ NpgsqlConnection.GlobalTypeMapper.MapEnum();
+ NpgsqlConnection.GlobalTypeMapper.MapEnum();
+ NpgsqlConnection.GlobalTypeMapper.MapEnum();
+ }
+
+ ///
+ /// A basic constructor that set default values (query tracker behaviors, mapping enums...)
+ ///
+ /// The connection string to use
+ /// Is this instance in debug mode?
+ public PostgresContext(string connection, bool debugMode)
+ {
+ _connection = connection;
+ _debugMode = debugMode;
+ }
+
+ ///
+ /// Set connection information for this database context
+ ///
+ /// An option builder to fill.
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ optionsBuilder.UseNpgsql(_connection);
+ if (_debugMode)
+ optionsBuilder.EnableDetailedErrors()
+ .EnableSensitiveDataLogging();
+ }
+
+ ///
+ /// Set database parameters to support every types of Kyoo.
+ ///
+ /// The database's model builder.
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ modelBuilder.HasPostgresEnum();
+ modelBuilder.HasPostgresEnum();
+ modelBuilder.HasPostgresEnum();
+
+ base.OnModelCreating(modelBuilder);
+ }
+
+ ///
+ protected override bool IsDuplicateException(Exception ex)
+ {
+ return ex.InnerException is PostgresException {SqlState: PostgresErrorCodes.UniqueViolation};
+ }
+ }
+}
\ No newline at end of file
diff --git a/Kyoo.Postgresql/PostgresModule.cs b/Kyoo.Postgresql/PostgresModule.cs
new file mode 100644
index 00000000..23549460
--- /dev/null
+++ b/Kyoo.Postgresql/PostgresModule.cs
@@ -0,0 +1,49 @@
+using System;
+using Kyoo.Controllers;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using Unity;
+using Unity.Injection;
+using Unity.Lifetime;
+using Unity.Resolution;
+
+namespace Kyoo.Postgresql
+{
+ ///
+ /// A module to add postgresql capacity to the app.
+ ///
+ public class PostgresModule : IPlugin
+ {
+ ///
+ public string Slug => "postgresql";
+
+ ///
+ public string Name => "Postgresql";
+
+ ///
+ public string Description => "A database context for postgresql.";
+
+ ///
+ public string[] Provides => new[]
+ {
+ $"{nameof(DatabaseContext)}:{nameof(PostgresContext)}"
+ };
+
+ ///
+ public string[] Requires => Array.Empty();
+
+ ///
+ public void Configure(IUnityContainer container, IConfiguration config, IApplicationBuilder app, bool debugMode)
+ {
+ // options.UseNpgsql(_configuration.GetDatabaseConnection());
+ // // // .EnableSensitiveDataLogging()
+ // // // .UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
+
+ container.RegisterFactory(_ =>
+ {
+ return new PostgresContext(config.GetDatabaseConnection(), debugMode);
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/Kyoo.Tests/Library/TestContext.cs b/Kyoo.Tests/Library/TestContext.cs
index c9a83ad0..e3cabc03 100644
--- a/Kyoo.Tests/Library/TestContext.cs
+++ b/Kyoo.Tests/Library/TestContext.cs
@@ -1,79 +1,79 @@
-using Kyoo.Models;
-using Microsoft.Data.Sqlite;
-using Microsoft.EntityFrameworkCore;
-
-namespace Kyoo.Tests
-{
- ///
- /// Class responsible to fill and create in memory databases for unit tests.
- ///
- public class TestContext
- {
- ///
- /// The context's options that specify to use an in memory Sqlite database.
- ///
- private readonly DbContextOptions _context;
-
- ///
- /// Create a new database and fill it with informations.
- ///
- public TestContext()
- {
- SqliteConnection connection = new("DataSource=:memory:");
- connection.Open();
-
- try
- {
- _context = new DbContextOptionsBuilder()
- .UseSqlite(connection)
- .Options;
- FillDatabase();
- }
- finally
- {
- connection.Close();
- }
- }
-
- ///
- /// Fill the database with pre defined values using a clean context.
- ///
- private void FillDatabase()
- {
- using DatabaseContext context = new(_context);
- context.Shows.Add(new Show
- {
- ID = 67,
- Slug = "anohana",
- Title = "Anohana: The Flower We Saw That Day",
- Aliases = new[]
- {
- "Ano Hi Mita Hana no Namae o Bokutachi wa Mada Shiranai.",
- "AnoHana",
- "We Still Don't Know the Name of the Flower We Saw That Day."
- },
- Overview = "When Yadomi Jinta was a child, he was a central piece in a group of close friends. " +
- "In time, however, these childhood friends drifted apart, and when they became high " +
- "school students, they had long ceased to think of each other as friends.",
- Status = Status.Finished,
- TrailerUrl = null,
- StartYear = 2011,
- EndYear = 2011,
- Poster = "poster",
- Logo = "logo",
- Backdrop = "backdrop",
- IsMovie = false,
- Studio = null
- });
- }
-
- ///
- /// Get a new databse context connected to a in memory Sqlite databse.
- ///
- /// A valid DatabaseContext
- public DatabaseContext New()
- {
- return new(_context);
- }
- }
-}
\ No newline at end of file
+// using Kyoo.Models;
+// using Microsoft.Data.Sqlite;
+// using Microsoft.EntityFrameworkCore;
+//
+// namespace Kyoo.Tests
+// {
+// ///
+// /// Class responsible to fill and create in memory databases for unit tests.
+// ///
+// public class TestContext
+// {
+// ///
+// /// The context's options that specify to use an in memory Sqlite database.
+// ///
+// private readonly DbContextOptions _context;
+//
+// ///
+// /// Create a new database and fill it with information.
+// ///
+// public TestContext()
+// {
+// SqliteConnection connection = new("DataSource=:memory:");
+// connection.Open();
+//
+// try
+// {
+// _context = new DbContextOptionsBuilder()
+// .UseSqlite(connection)
+// .Options;
+// FillDatabase();
+// }
+// finally
+// {
+// connection.Close();
+// }
+// }
+//
+// ///
+// /// Fill the database with pre defined values using a clean context.
+// ///
+// private void FillDatabase()
+// {
+// using DatabaseContext context = new(_context);
+// context.Shows.Add(new Show
+// {
+// ID = 67,
+// Slug = "anohana",
+// Title = "Anohana: The Flower We Saw That Day",
+// Aliases = new[]
+// {
+// "Ano Hi Mita Hana no Namae o Bokutachi wa Mada Shiranai.",
+// "AnoHana",
+// "We Still Don't Know the Name of the Flower We Saw That Day."
+// },
+// Overview = "When Yadomi Jinta was a child, he was a central piece in a group of close friends. " +
+// "In time, however, these childhood friends drifted apart, and when they became high " +
+// "school students, they had long ceased to think of each other as friends.",
+// Status = Status.Finished,
+// TrailerUrl = null,
+// StartYear = 2011,
+// EndYear = 2011,
+// Poster = "poster",
+// Logo = "logo",
+// Backdrop = "backdrop",
+// IsMovie = false,
+// Studio = null
+// });
+// }
+//
+// ///
+// /// Get a new database context connected to a in memory Sqlite database.
+// ///
+// /// A valid DatabaseContext
+// public DatabaseContext New()
+// {
+// return new(_context);
+// }
+// }
+// }
\ No newline at end of file
diff --git a/Kyoo.sln b/Kyoo.sln
index 0eb53fe3..79ee6e7d 100644
--- a/Kyoo.sln
+++ b/Kyoo.sln
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.CommonAPI", "Kyoo.Comm
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Tests", "Kyoo.Tests\Kyoo.Tests.csproj", "{D179D5FF-9F75-4B27-8E27-0DBDF1806611}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Postgresql", "Kyoo.Postgresql\Kyoo.Postgresql.csproj", "{3213C96D-0BF3-460B-A8B5-B9977229408A}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -29,5 +31,9 @@ Global
{D179D5FF-9F75-4B27-8E27-0DBDF1806611}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D179D5FF-9F75-4B27-8E27-0DBDF1806611}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D179D5FF-9F75-4B27-8E27-0DBDF1806611}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3213C96D-0BF3-460B-A8B5-B9977229408A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3213C96D-0BF3-460B-A8B5-B9977229408A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3213C96D-0BF3-460B-A8B5-B9977229408A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3213C96D-0BF3-460B-A8B5-B9977229408A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
diff --git a/Kyoo/Controllers/Repositories/LibraryItemRepository.cs b/Kyoo/Controllers/Repositories/LibraryItemRepository.cs
index 43afd407..c1db8e46 100644
--- a/Kyoo/Controllers/Repositories/LibraryItemRepository.cs
+++ b/Kyoo/Controllers/Repositories/LibraryItemRepository.cs
@@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@@ -20,10 +19,6 @@ namespace Kyoo.Controllers
///
private readonly DatabaseContext _database;
///
- /// A provider repository to handle externalID creation and deletion
- ///
- private readonly IProviderRepository _providers;
- ///
/// A lazy loaded library repository to validate queries (check if a library does exist)
///
private readonly Lazy _libraries;
@@ -44,18 +39,19 @@ namespace Kyoo.Controllers
/// Create a new .
///
/// The databse instance
- /// A provider repository
- /// A service provider to lazilly request a library, show or collection repository.
+ /// A lazy loaded library repository
+ /// A lazy loaded show repository
+ /// A lazy loaded collection repository
public LibraryItemRepository(DatabaseContext database,
- IProviderRepository providers,
- IServiceProvider services)
+ Lazy libraries,
+ Lazy shows,
+ Lazy collections)
: base(database)
{
_database = database;
- _providers = providers;
- _libraries = new Lazy(services.GetRequiredService);
- _shows = new Lazy(services.GetRequiredService);
- _collections = new Lazy(services.GetRequiredService);
+ _libraries = libraries;
+ _shows = shows;
+ _collections = collections;
}
diff --git a/Kyoo/Controllers/Repositories/PeopleRepository.cs b/Kyoo/Controllers/Repositories/PeopleRepository.cs
index 526a3286..6de72a4b 100644
--- a/Kyoo/Controllers/Repositories/PeopleRepository.cs
+++ b/Kyoo/Controllers/Repositories/PeopleRepository.cs
@@ -36,15 +36,15 @@ namespace Kyoo.Controllers
///
/// The database handle
/// A provider repository
- /// A service provider to lazy load a show repository
+ /// A lazy loaded show repository
public PeopleRepository(DatabaseContext database,
IProviderRepository providers,
- IServiceProvider services)
+ Lazy shows)
: base(database)
{
_database = database;
_providers = providers;
- _shows = new Lazy(services.GetRequiredService);
+ _shows = shows;
}
diff --git a/Kyoo/Controllers/Repositories/SeasonRepository.cs b/Kyoo/Controllers/Repositories/SeasonRepository.cs
index e35042ad..b0a61c90 100644
--- a/Kyoo/Controllers/Repositories/SeasonRepository.cs
+++ b/Kyoo/Controllers/Repositories/SeasonRepository.cs
@@ -7,7 +7,6 @@ using System.Threading.Tasks;
using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@@ -44,17 +43,17 @@ namespace Kyoo.Controllers
/// The database handle that will be used
/// A provider repository
/// A show repository
- /// A service provider to lazilly request an episode repository.
+ /// A lazy loaded episode repository.
public SeasonRepository(DatabaseContext database,
IProviderRepository providers,
IShowRepository shows,
- IServiceProvider services)
+ Lazy episodes)
: base(database)
{
_database = database;
_providers = providers;
_shows = shows;
- _episodes = new Lazy(services.GetRequiredService);
+ _episodes = episodes;
}
diff --git a/Kyoo/Controllers/Repositories/ShowRepository.cs b/Kyoo/Controllers/Repositories/ShowRepository.cs
index 1129cd07..07d2cafd 100644
--- a/Kyoo/Controllers/Repositories/ShowRepository.cs
+++ b/Kyoo/Controllers/Repositories/ShowRepository.cs
@@ -5,7 +5,6 @@ using System.Linq.Expressions;
using System.Threading.Tasks;
using Kyoo.Models;
using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Controllers
{
@@ -54,13 +53,15 @@ namespace Kyoo.Controllers
/// A people repository
/// A genres repository
/// A provider repository
- /// A service provider to lazilly request a season and an episode repository
+ /// A lazy loaded season repository
+ /// A lazy loaded episode repository
public ShowRepository(DatabaseContext database,
IStudioRepository studios,
IPeopleRepository people,
IGenreRepository genres,
IProviderRepository providers,
- IServiceProvider services)
+ Lazy seasons,
+ Lazy episodes)
: base(database)
{
_database = database;
@@ -68,8 +69,8 @@ namespace Kyoo.Controllers
_people = people;
_genres = genres;
_providers = providers;
- _seasons = new Lazy(services.GetRequiredService);
- _episodes = new Lazy(services.GetRequiredService);
+ _seasons = seasons;
+ _episodes = episodes;
}
diff --git a/Kyoo/Controllers/TaskManager.cs b/Kyoo/Controllers/TaskManager.cs
index e93c050f..a625dcf2 100644
--- a/Kyoo/Controllers/TaskManager.cs
+++ b/Kyoo/Controllers/TaskManager.cs
@@ -62,10 +62,10 @@ namespace Kyoo.Controllers
IConfiguration configuration,
ILogger logger)
{
- _tasks = tasks.Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
_container = container;
_configuration = configuration.GetSection("scheduledTasks");
_logger = logger;
+ _tasks = tasks.Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
}
@@ -179,8 +179,10 @@ namespace Kyoo.Controllers
}
///
- public void StartTask(string taskSlug, Dictionary arguments)
+ public void StartTask(string taskSlug, Dictionary arguments = null)
{
+ arguments ??= new Dictionary();
+
int index = _tasks.FindIndex(x => x.task.Slug == taskSlug);
if (index == -1)
throw new ItemNotFound($"No task found with the slug {taskSlug}");
@@ -216,7 +218,7 @@ namespace Kyoo.Controllers
///
public void ReloadTasks()
{
- _tasks = _container.ResolveAll().Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
+ _tasks = _container.Resolve>().Select(x => (x, DateTime.Now + GetTaskDelay(x.Slug))).ToList();
EnqueueStartupTasks();
}
}
diff --git a/Kyoo/CoreModule.cs b/Kyoo/CoreModule.cs
index d194a267..26e12c80 100644
--- a/Kyoo/CoreModule.cs
+++ b/Kyoo/CoreModule.cs
@@ -1,10 +1,14 @@
using Kyoo.Controllers;
+using Kyoo.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.Configuration;
using Unity;
+using Unity.Lifetime;
namespace Kyoo
{
///
- /// The core module ccontaining default implementations
+ /// The core module containing default implementations
///
public class CoreModule : IPlugin
{
@@ -17,10 +21,60 @@ namespace Kyoo
///
public string Description => "The core module containing default implementations.";
- ///
- public static void Configure(IUnityContainer container)
+ ///
+ public string[] Provides => new[]
{
- container.AddTask();
+ $"{nameof(IFileManager)}:file",
+ $"{nameof(ITranscoder)}:{nameof(Transcoder)}",
+ $"{nameof(IThumbnailsManager)}:{nameof(ThumbnailsManager)}",
+ $"{nameof(IProviderManager)}:{nameof(ProviderManager)}",
+ $"{nameof(IPluginManager)}:{nameof(PluginManager)}",
+ $"{nameof(ITaskManager)}:{nameof(TaskManager)}",
+ $"{nameof(ILibraryManager)}:{nameof(LibraryManager)}",
+ $"{nameof(ILibraryRepository)}:{nameof(LibraryRepository)}",
+ $"{nameof(ILibraryItemRepository)}:{nameof(LibraryItemRepository)}",
+ $"{nameof(ICollectionRepository)}:{nameof(CollectionRepository)}",
+ $"{nameof(IShowRepository)}:{nameof(ShowRepository)}",
+ $"{nameof(ISeasonRepository)}:{nameof(SeasonRepository)}",
+ $"{nameof(IEpisodeRepository)}:{nameof(EpisodeRepository)}",
+ $"{nameof(ITrackRepository)}:{nameof(TrackRepository)}",
+ $"{nameof(IPeopleRepository)}:{nameof(PeopleRepository)}",
+ $"{nameof(IStudioRepository)}:{nameof(StudioRepository)}",
+ $"{nameof(IGenreRepository)}:{nameof(GenreRepository)}",
+ $"{nameof(IProviderRepository)}:{nameof(ProviderRepository)}"
+ };
+
+ ///
+ public string[] Requires => new[]
+ {
+ "DatabaseContext:"
+ };
+
+ ///
+ public void Configure(IUnityContainer container, IConfiguration config, IApplicationBuilder app, bool debugMode)
+ {
+ container.RegisterType(new SingletonLifetimeManager());
+ container.RegisterType(new SingletonLifetimeManager());
+ container.RegisterType(new SingletonLifetimeManager());
+ container.RegisterType(new SingletonLifetimeManager());
+ container.RegisterType(new SingletonLifetimeManager());
+ container.RegisterType(new SingletonLifetimeManager());
+
+ container.RegisterType(new HierarchicalLifetimeManager());
+
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+ container.RegisterType(new HierarchicalLifetimeManager());
+
+ container.RegisterTask();
}
}
}
\ No newline at end of file
diff --git a/Kyoo/Models/DatabaseContext.cs b/Kyoo/Models/DatabaseContext.cs
index 577e9903..caf8933e 100644
--- a/Kyoo/Models/DatabaseContext.cs
+++ b/Kyoo/Models/DatabaseContext.cs
@@ -7,17 +7,17 @@ using Kyoo.Models;
using Kyoo.Models.Exceptions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
-using Npgsql;
namespace Kyoo
{
///
/// The database handle used for all local repositories.
+ /// This is an abstract class. It is meant to be implemented by plugins. This allow the core to be database agnostic.
///
///
/// It should not be used directly, to access the database use a or repositories.
///
- public class DatabaseContext : DbContext
+ public abstract class DatabaseContext : DbContext
{
///
/// All libraries of Kyoo. See .
@@ -89,10 +89,6 @@ namespace Kyoo
///
public DatabaseContext()
{
- NpgsqlConnection.GlobalTypeMapper.MapEnum();
- NpgsqlConnection.GlobalTypeMapper.MapEnum();
- NpgsqlConnection.GlobalTypeMapper.MapEnum();
-
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
ChangeTracker.LazyLoadingEnabled = false;
}
@@ -100,7 +96,7 @@ namespace Kyoo
///
/// Create a new .
///
- /// Connection options to use (witch databse provider to use, connection strings...)
+ /// Connection options to use (witch database provider to use, connection strings...)
public DatabaseContext(DbContextOptions options)
: base(options)
{
@@ -116,10 +112,6 @@ namespace Kyoo
{
base.OnModelCreating(modelBuilder);
- modelBuilder.HasPostgresEnum();
- modelBuilder.HasPostgresEnum();
- modelBuilder.HasPostgresEnum();
-
modelBuilder.Entity