mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-05 21:37:10 -04:00
Update ApplicationHost.cs
This commit is contained in:
parent
0738a2dc4b
commit
ba685d8092
@ -128,7 +128,7 @@ namespace Emby.Server.Implementations
|
||||
private ISessionManager _sessionManager;
|
||||
private IHttpClientFactory _httpClientFactory;
|
||||
private IWebSocketManager _webSocketManager;
|
||||
|
||||
private Dictionary<Type, Assembly> _pluginRegistrations;
|
||||
private string[] _urlPrefixes;
|
||||
|
||||
/// <summary>
|
||||
@ -262,6 +262,8 @@ namespace Emby.Server.Implementations
|
||||
|
||||
ServiceCollection = serviceCollection;
|
||||
|
||||
_pluginRegistrations = new Dictionary<Type, Assembly>();
|
||||
|
||||
_networkManager = networkManager;
|
||||
networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets;
|
||||
|
||||
@ -499,24 +501,11 @@ namespace Emby.Server.Implementations
|
||||
HttpsPort = ServerConfiguration.DefaultHttpsPort;
|
||||
}
|
||||
|
||||
if (Plugins != null)
|
||||
{
|
||||
var pluginBuilder = new StringBuilder();
|
||||
|
||||
foreach (var plugin in Plugins)
|
||||
{
|
||||
pluginBuilder.Append(plugin.Name)
|
||||
.Append(' ')
|
||||
.Append(plugin.Version)
|
||||
.AppendLine();
|
||||
}
|
||||
|
||||
Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString());
|
||||
}
|
||||
|
||||
DiscoverTypes();
|
||||
|
||||
RegisterServices();
|
||||
|
||||
RegisterPlugIns();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -781,10 +770,24 @@ namespace Emby.Server.Implementations
|
||||
|
||||
ConfigurationManager.AddParts(GetExports<IConfigurationFactory>());
|
||||
_plugins = GetExports<IPlugin>()
|
||||
.Select(LoadPlugin)
|
||||
.Where(i => i != null)
|
||||
.ToArray();
|
||||
|
||||
if (Plugins != null)
|
||||
{
|
||||
var pluginBuilder = new StringBuilder();
|
||||
|
||||
foreach (var plugin in Plugins)
|
||||
{
|
||||
pluginBuilder.Append(plugin.Name)
|
||||
.Append(' ')
|
||||
.Append(plugin.Version)
|
||||
.AppendLine();
|
||||
}
|
||||
|
||||
Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString());
|
||||
}
|
||||
|
||||
_urlPrefixes = GetUrlPrefixes().ToArray();
|
||||
_webSocketManager.Init(GetExports<IWebSocketListener>());
|
||||
|
||||
@ -850,8 +853,6 @@ namespace Emby.Server.Implementations
|
||||
{
|
||||
hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s));
|
||||
}
|
||||
|
||||
plugin.RegisterServices(ServiceCollection);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -872,6 +873,24 @@ namespace Emby.Server.Implementations
|
||||
_allConcreteTypes = GetTypes(GetComposablePartAssemblies()).ToArray();
|
||||
}
|
||||
|
||||
private void RegisterPlugIns()
|
||||
{
|
||||
foreach ((var pluginType, var assembly) in _pluginRegistrations)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pluginRegistration = Activator.CreateInstance(pluginType);
|
||||
pluginType.InvokeMember("RegisterServices", BindingFlags.InvokeMethod, null, pluginRegistration, new object[] { ServiceCollection }, CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Error registering {Assembly} with D.I.", assembly);
|
||||
}
|
||||
}
|
||||
|
||||
_pluginRegistrations.Clear();
|
||||
}
|
||||
|
||||
private IEnumerable<Type> GetTypes(IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
foreach (var ass in assemblies)
|
||||
@ -881,19 +900,10 @@ namespace Emby.Server.Implementations
|
||||
{
|
||||
exportedTypes = ass.GetExportedTypes();
|
||||
|
||||
try
|
||||
{
|
||||
Type reg = (Type)exportedTypes.Where(p => string.Equals(p.Name, "PluginRegistration", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (reg != null)
|
||||
{
|
||||
var pluginRegistration = Activator.CreateInstance(reg);
|
||||
reg.InvokeMember("RegisterServices", BindingFlags.InvokeMethod, null, pluginRegistration, new object[] { ServiceCollection }, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Error registering {Assembly} with D.I.", ass.FullName);
|
||||
continue;
|
||||
_pluginRegistrations.Add(ass, reg);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
|
Loading…
Reference in New Issue
Block a user