mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
handle type creation errors
This commit is contained in:
parent
9a4712cf22
commit
76faf89aca
@ -384,7 +384,7 @@ namespace MediaBrowser.Common.Implementations
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">The type.</param>
|
/// <param name="type">The type.</param>
|
||||||
/// <returns>System.Object.</returns>
|
/// <returns>System.Object.</returns>
|
||||||
public object CreateInstance(Type type)
|
protected object CreateInstance(Type type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -398,6 +398,25 @@ namespace MediaBrowser.Common.Implementations
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the instance safe.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The type.</param>
|
||||||
|
/// <returns>System.Object.</returns>
|
||||||
|
protected object CreateInstanceSafe(Type type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Container.GetInstance(type);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Error("Error creating {0}", ex, type.Name);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers the specified obj.
|
/// Registers the specified obj.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -496,7 +515,11 @@ namespace MediaBrowser.Common.Implementations
|
|||||||
/// <returns>IEnumerable{``0}.</returns>
|
/// <returns>IEnumerable{``0}.</returns>
|
||||||
public IEnumerable<T> GetExports<T>(bool manageLiftime = true)
|
public IEnumerable<T> GetExports<T>(bool manageLiftime = true)
|
||||||
{
|
{
|
||||||
var parts = GetExportTypes<T>().Select(CreateInstance).Cast<T>().ToList();
|
var parts = GetExportTypes<T>()
|
||||||
|
.Select(CreateInstanceSafe)
|
||||||
|
.Where(i => i != null)
|
||||||
|
.Cast<T>()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
if (manageLiftime)
|
if (manageLiftime)
|
||||||
{
|
{
|
||||||
|
@ -89,13 +89,6 @@ namespace MediaBrowser.Common
|
|||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress);
|
Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an instance of type and resolves all constructor dependancies
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">The type.</param>
|
|
||||||
/// <returns>System.Object.</returns>
|
|
||||||
object CreateInstance(Type type);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resolves this instance.
|
/// Resolves this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user