aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2019-02-06 14:04:32 +0100
committerBond-009 <bond.009@outlook.com>2019-02-12 20:52:23 +0100
commit9af28607c990f5ddcd738c72d7183b9a57ba47c2 (patch)
treef5d5f7b61f9d47d8c97ce63c85a724f20abf6987
parent81a8ebde22e92c9d8f4292bfb18c9134f43bd956 (diff)
Simplify plugin loading
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs45
-rw-r--r--Jellyfin.Server/CoreAppHost.cs4
2 files changed, 13 insertions, 36 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index b9d38504c..5dcf42aae 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -303,7 +303,6 @@ namespace Emby.Server.Implementations
/// <value>The user data repository.</value>
private IUserDataManager UserDataManager { get; set; }
private IUserRepository UserRepository { get; set; }
- internal IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
internal SqliteItemRepository ItemRepository { get; set; }
private INotificationManager NotificationManager { get; set; }
@@ -472,6 +471,7 @@ namespace Emby.Server.Implementations
{
try
{
+ Logger.LogWarning("Creating instance of {Type}", type);
return ActivatorUtilities.CreateInstance(_serviceProvider, type);
}
catch (Exception ex)
@@ -525,29 +525,6 @@ namespace Emby.Server.Implementations
return parts;
}
- public List<(T, string)> GetExportsWithInfo<T>(bool manageLifetime = true)
- {
- var parts = GetExportTypes<T>()
- .Select(i =>
- {
- var obj = CreateInstanceSafe(i);
-
- return ((T)obj, i.Assembly.Location);
- })
- .Where(i => i.Item1 != null)
- .ToList();
-
- if (manageLifetime)
- {
- lock (DisposableParts)
- {
- DisposableParts.AddRange(parts.Select(i => i.Item1).OfType<IDisposable>());
- }
- }
-
- return parts;
- }
-
/// <summary>
/// Runs the startup tasks.
/// </summary>
@@ -721,8 +698,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton(UserRepository);
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LoggerFactory, JsonSerializer, ApplicationPaths, FileSystemManager);
- DisplayPreferencesRepository = displayPreferencesRepo;
- serviceCollection.AddSingleton(DisplayPreferencesRepository);
+ serviceCollection.AddSingleton<IDisplayPreferencesRepository>(displayPreferencesRepo);
ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, assemblyInfo);
serviceCollection.AddSingleton<IItemRepository>(ItemRepository);
@@ -1085,7 +1061,10 @@ namespace Emby.Server.Implementations
}
ConfigurationManager.AddParts(GetExports<IConfigurationFactory>());
- Plugins = GetExportsWithInfo<IPlugin>().Select(LoadPlugin).Where(i => i != null).ToArray();
+ Plugins = GetExports<IPlugin>()
+ .Select(LoadPlugin)
+ .Where(i => i != null)
+ .ToArray();
HttpServer.Init(GetExports<IService>(false), GetExports<IWebSocketListener>());
@@ -1119,19 +1098,15 @@ namespace Emby.Server.Implementations
IsoManager.AddParts(GetExports<IIsoMounter>());
}
- private IPlugin LoadPlugin((IPlugin, string) info)
+ private IPlugin LoadPlugin(IPlugin plugin)
{
- var plugin = info.Item1;
- var assemblyFilePath = info.Item2;
-
try
{
- var assemblyPlugin = plugin as IPluginAssembly;
-
- if (assemblyPlugin != null)
+ if (plugin is IPluginAssembly assemblyPlugin)
{
var assembly = plugin.GetType().Assembly;
var assemblyName = assembly.GetName();
+ var assemblyFilePath = assembly.Location;
var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath));
@@ -1401,7 +1376,7 @@ namespace Emby.Server.Implementations
foreach (var file in Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly))
{
Logger.LogInformation("Loading assembly {Path}", file);
- yield return Assembly.LoadFile(file);
+ yield return Assembly.LoadFrom(file);
}
}
diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs
index 315e34a04..a486c2a47 100644
--- a/Jellyfin.Server/CoreAppHost.cs
+++ b/Jellyfin.Server/CoreAppHost.cs
@@ -21,7 +21,9 @@ namespace Jellyfin.Server
protected override void RestartInternal() => Program.Restart();
protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
- => new[] { typeof(CoreAppHost).Assembly };
+ {
+ yield return typeof(CoreAppHost).Assembly;
+ }
protected override void ShutdownInternal() => Program.Shutdown();