mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
added simple injector for dependancy management
This commit is contained in:
parent
107c241598
commit
a2d215b6ae
@ -1,5 +1,4 @@
|
|||||||
using MediaBrowser.Common.Mef;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
@ -213,7 +212,7 @@ namespace MediaBrowser.Api
|
|||||||
{
|
{
|
||||||
var kernel = (Kernel)Kernel;
|
var kernel = (Kernel)Kernel;
|
||||||
|
|
||||||
var allTypes = kernel.Assemblies.SelectMany(MefUtils.GetTypes).Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(BaseItem)));
|
var allTypes = kernel.AllTypes.Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(BaseItem)));
|
||||||
|
|
||||||
if (request.HasInternetProvider)
|
if (request.HasInternetProvider)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
using MediaBrowser.Common.Events;
|
using MediaBrowser.Common.Events;
|
||||||
using MediaBrowser.Common.IO;
|
using MediaBrowser.Common.IO;
|
||||||
using MediaBrowser.Common.Localization;
|
|
||||||
using MediaBrowser.Common.Mef;
|
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Common.ScheduledTasks;
|
using MediaBrowser.Common.ScheduledTasks;
|
||||||
@ -13,12 +11,14 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.ComponentModel.Composition.Hosting;
|
using System.ComponentModel.Composition.Hosting;
|
||||||
|
using System.ComponentModel.Composition.Primitives;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using SimpleInjector;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Kernel
|
namespace MediaBrowser.Common.Kernel
|
||||||
{
|
{
|
||||||
@ -200,13 +200,6 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
[ImportMany(typeof(IWebSocketListener))]
|
[ImportMany(typeof(IWebSocketListener))]
|
||||||
public IEnumerable<IWebSocketListener> WebSocketListeners { get; private set; }
|
public IEnumerable<IWebSocketListener> WebSocketListeners { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the list of Localized string files
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The string files.</value>
|
|
||||||
[ImportMany(typeof(LocalizedStringData))]
|
|
||||||
public IEnumerable<LocalizedStringData> StringFiles { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the MEF CompositionContainer
|
/// Gets the MEF CompositionContainer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -241,7 +234,6 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
/// Gets the rest services.
|
/// Gets the rest services.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The rest services.</value>
|
/// <value>The rest services.</value>
|
||||||
[ImportMany(typeof(IRestfulService))]
|
|
||||||
public IEnumerable<IRestfulService> RestServices { get; private set; }
|
public IEnumerable<IRestfulService> RestServices { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -265,7 +257,7 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
// Lazy load
|
// Lazy load
|
||||||
LazyInitializer.EnsureInitialized(ref _protobufSerializer, ref _protobufSerializerInitialized, ref _protobufSerializerSyncLock, () => DynamicProtobufSerializer.Create(Assemblies));
|
LazyInitializer.EnsureInitialized(ref _protobufSerializer, ref _protobufSerializerInitialized, ref _protobufSerializerSyncLock, () => DynamicProtobufSerializer.Create(AllTypes));
|
||||||
return _protobufSerializer;
|
return _protobufSerializer;
|
||||||
}
|
}
|
||||||
private set
|
private set
|
||||||
@ -341,6 +333,12 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
/// <value>The assemblies.</value>
|
/// <value>The assemblies.</value>
|
||||||
public Assembly[] Assemblies { get; private set; }
|
public Assembly[] Assemblies { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all types.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>All types.</value>
|
||||||
|
public Type[] AllTypes { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="BaseKernel{TApplicationPathsType}" /> class.
|
/// Initializes a new instance of the <see cref="BaseKernel{TApplicationPathsType}" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -460,25 +458,83 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
|
|
||||||
Assemblies = GetComposablePartAssemblies().ToArray();
|
Assemblies = GetComposablePartAssemblies().ToArray();
|
||||||
|
|
||||||
CompositionContainer = MefUtils.GetSafeCompositionContainer(Assemblies.Select(i => new AssemblyCatalog(i)));
|
AllTypes = Assemblies.SelectMany(GetTypes).ToArray();
|
||||||
|
|
||||||
ComposeExportedValues(CompositionContainer);
|
ComposeParts(AllTypes);
|
||||||
|
|
||||||
CompositionContainer.ComposeParts(this);
|
|
||||||
|
|
||||||
await OnComposablePartsLoaded().ConfigureAwait(false);
|
await OnComposablePartsLoaded().ConfigureAwait(false);
|
||||||
|
|
||||||
CompositionContainer.Catalog.Dispose();
|
CompositionContainer.Catalog.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ioc container
|
||||||
|
/// </summary>
|
||||||
|
private readonly Container _iocContainer = new Container();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Composes the parts.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="allTypes">All types.</param>
|
||||||
|
private void ComposeParts(IEnumerable<Type> allTypes)
|
||||||
|
{
|
||||||
|
var concreteTypes = allTypes.Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && !t.IsGenericType).ToArray();
|
||||||
|
|
||||||
|
CompositionContainer = GetSafeCompositionContainer(concreteTypes.Select(i => new TypeCatalog(i)));
|
||||||
|
|
||||||
|
ComposeExportedValues(CompositionContainer, _iocContainer);
|
||||||
|
|
||||||
|
CompositionContainer.ComposeParts(this);
|
||||||
|
|
||||||
|
ComposePartsWithIocContainer(concreteTypes, _iocContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Composes the parts with ioc container.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="allTypes">All types.</param>
|
||||||
|
/// <param name="container">The container.</param>
|
||||||
|
protected virtual void ComposePartsWithIocContainer(Type[] allTypes, Container container)
|
||||||
|
{
|
||||||
|
RestServices = GetExports<IRestfulService>(allTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the exports.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="allTypes">All types.</param>
|
||||||
|
/// <returns>IEnumerable{``0}.</returns>
|
||||||
|
protected IEnumerable<T> GetExports<T>(Type[] allTypes)
|
||||||
|
{
|
||||||
|
var currentType = typeof(T);
|
||||||
|
|
||||||
|
Logger.Info("Composing instances of " + currentType.Name);
|
||||||
|
|
||||||
|
return allTypes.Where(currentType.IsAssignableFrom).Select(Instantiate).Cast<T>().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The type.</param>
|
||||||
|
/// <returns>System.Object.</returns>
|
||||||
|
private object Instantiate(Type type)
|
||||||
|
{
|
||||||
|
return _iocContainer.GetInstance(type);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Composes the exported values.
|
/// Composes the exported values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="container">The container.</param>
|
/// <param name="container">The container.</param>
|
||||||
protected virtual void ComposeExportedValues(CompositionContainer container)
|
protected virtual void ComposeExportedValues(CompositionContainer container, Container iocContainer)
|
||||||
{
|
{
|
||||||
container.ComposeExportedValue("logger", Logger);
|
container.ComposeExportedValue("logger", Logger);
|
||||||
container.ComposeExportedValue("appHost", ApplicationHost);
|
container.ComposeExportedValue("appHost", ApplicationHost);
|
||||||
|
|
||||||
|
iocContainer.RegisterSingle(Logger);
|
||||||
|
iocContainer.RegisterSingle(ApplicationHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -545,6 +601,71 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
yield return GetType().Assembly;
|
yield return GetType().Assembly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins that live on both the server and UI are going to have references to assemblies from both sides.
|
||||||
|
/// But looks for Parts on one side, it will throw an exception when it seems Types from the other side that it doesn't have a reference to.
|
||||||
|
/// For example, a plugin provides a Resolver. When MEF runs in the UI, it will throw an exception when it sees the resolver because there won't be a reference to the base class.
|
||||||
|
/// This method will catch those exceptions while retining the list of Types that MEF is able to resolve.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="catalogs">The catalogs.</param>
|
||||||
|
/// <returns>CompositionContainer.</returns>
|
||||||
|
/// <exception cref="System.ArgumentNullException">catalogs</exception>
|
||||||
|
private static CompositionContainer GetSafeCompositionContainer(IEnumerable<ComposablePartCatalog> catalogs)
|
||||||
|
{
|
||||||
|
if (catalogs == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("catalogs");
|
||||||
|
}
|
||||||
|
|
||||||
|
var newList = new List<ComposablePartCatalog>();
|
||||||
|
|
||||||
|
// Go through each Catalog
|
||||||
|
foreach (var catalog in catalogs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Try to have MEF find Parts
|
||||||
|
catalog.Parts.ToArray();
|
||||||
|
|
||||||
|
// If it succeeds we can use the entire catalog
|
||||||
|
newList.Add(catalog);
|
||||||
|
}
|
||||||
|
catch (ReflectionTypeLoadException ex)
|
||||||
|
{
|
||||||
|
// If it fails we can still get a list of the Types it was able to resolve and create TypeCatalogs
|
||||||
|
var typeCatalogs = ex.Types.Where(t => t != null).Select(t => new TypeCatalog(t));
|
||||||
|
newList.AddRange(typeCatalogs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CompositionContainer(new AggregateCatalog(newList));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a list of types within an assembly
|
||||||
|
/// This will handle situations that would normally throw an exception - such as a type within the assembly that depends on some other non-existant reference
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly">The assembly.</param>
|
||||||
|
/// <returns>IEnumerable{Type}.</returns>
|
||||||
|
/// <exception cref="System.ArgumentNullException">assembly</exception>
|
||||||
|
private static IEnumerable<Type> GetTypes(Assembly assembly)
|
||||||
|
{
|
||||||
|
if (assembly == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("assembly");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return assembly.GetTypes();
|
||||||
|
}
|
||||||
|
catch (ReflectionTypeLoadException ex)
|
||||||
|
{
|
||||||
|
// If it fails we can still get a list of the Types it was able to resolve
|
||||||
|
return ex.Types.Where(t => t != null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires after MEF finishes finding composable parts within plugin assemblies
|
/// Fires after MEF finishes finding composable parts within plugin assemblies
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -88,6 +88,9 @@
|
|||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\packages\ServiceStack.Text.3.9.37\lib\net35\ServiceStack.Text.dll</HintPath>
|
<HintPath>..\packages\ServiceStack.Text.3.9.37\lib\net35\ServiceStack.Text.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="SimpleInjector">
|
||||||
|
<HintPath>..\packages\SimpleInjector.2.0.0-beta5\lib\net40-client\SimpleInjector.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.ComponentModel.Composition" />
|
<Reference Include="System.ComponentModel.Composition" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
@ -139,7 +142,6 @@
|
|||||||
<Compile Include="Kernel\IKernel.cs" />
|
<Compile Include="Kernel\IKernel.cs" />
|
||||||
<Compile Include="Kernel\TcpManager.cs" />
|
<Compile Include="Kernel\TcpManager.cs" />
|
||||||
<Compile Include="Localization\LocalizedStringData.cs" />
|
<Compile Include="Localization\LocalizedStringData.cs" />
|
||||||
<Compile Include="Mef\MefUtils.cs" />
|
|
||||||
<Compile Include="Net\AlchemyWebSocket.cs" />
|
<Compile Include="Net\AlchemyWebSocket.cs" />
|
||||||
<Compile Include="Net\BaseRestService.cs" />
|
<Compile Include="Net\BaseRestService.cs" />
|
||||||
<Compile Include="Net\Handlers\BaseActionHandler.cs" />
|
<Compile Include="Net\Handlers\BaseActionHandler.cs" />
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.Composition.Hosting;
|
|
||||||
using System.ComponentModel.Composition.Primitives;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Mef
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Class MefUtils
|
|
||||||
/// </summary>
|
|
||||||
public static class MefUtils
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Plugins that live on both the server and UI are going to have references to assemblies from both sides.
|
|
||||||
/// But looks for Parts on one side, it will throw an exception when it seems Types from the other side that it doesn't have a reference to.
|
|
||||||
/// For example, a plugin provides a Resolver. When MEF runs in the UI, it will throw an exception when it sees the resolver because there won't be a reference to the base class.
|
|
||||||
/// This method will catch those exceptions while retining the list of Types that MEF is able to resolve.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="catalogs">The catalogs.</param>
|
|
||||||
/// <returns>CompositionContainer.</returns>
|
|
||||||
/// <exception cref="System.ArgumentNullException">catalogs</exception>
|
|
||||||
public static CompositionContainer GetSafeCompositionContainer(IEnumerable<ComposablePartCatalog> catalogs)
|
|
||||||
{
|
|
||||||
if (catalogs == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("catalogs");
|
|
||||||
}
|
|
||||||
|
|
||||||
var newList = new List<ComposablePartCatalog>();
|
|
||||||
|
|
||||||
// Go through each Catalog
|
|
||||||
foreach (var catalog in catalogs)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Try to have MEF find Parts
|
|
||||||
catalog.Parts.ToArray();
|
|
||||||
|
|
||||||
// If it succeeds we can use the entire catalog
|
|
||||||
newList.Add(catalog);
|
|
||||||
}
|
|
||||||
catch (ReflectionTypeLoadException ex)
|
|
||||||
{
|
|
||||||
// If it fails we can still get a list of the Types it was able to resolve and create TypeCatalogs
|
|
||||||
var typeCatalogs = ex.Types.Where(t => t != null).Select(t => new TypeCatalog(t));
|
|
||||||
newList.AddRange(typeCatalogs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CompositionContainer(new AggregateCatalog(newList));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a list of types within an assembly
|
|
||||||
/// This will handle situations that would normally throw an exception - such as a type within the assembly that depends on some other non-existant reference
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="assembly">The assembly.</param>
|
|
||||||
/// <returns>IEnumerable{Type}.</returns>
|
|
||||||
/// <exception cref="System.ArgumentNullException">assembly</exception>
|
|
||||||
public static IEnumerable<Type> GetTypes(Assembly assembly)
|
|
||||||
{
|
|
||||||
if (assembly == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("assembly");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return assembly.GetTypes();
|
|
||||||
}
|
|
||||||
catch (ReflectionTypeLoadException ex)
|
|
||||||
{
|
|
||||||
// If it fails we can still get a list of the Types it was able to resolve
|
|
||||||
return ex.Types.Where(t => t != null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,9 @@
|
|||||||
using MediaBrowser.Common.Mef;
|
using ProtoBuf;
|
||||||
using ProtoBuf;
|
|
||||||
using ProtoBuf.Meta;
|
using ProtoBuf.Meta;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Serialization
|
namespace MediaBrowser.Common.Serialization
|
||||||
{
|
{
|
||||||
@ -135,21 +133,20 @@ namespace MediaBrowser.Common.Serialization
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the specified assemblies.
|
/// Creates the specified assemblies.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="assemblies">The assemblies.</param>
|
|
||||||
/// <returns>DynamicProtobufSerializer.</returns>
|
/// <returns>DynamicProtobufSerializer.</returns>
|
||||||
/// <exception cref="System.ArgumentNullException">assemblies</exception>
|
/// <exception cref="System.ArgumentNullException">assemblies</exception>
|
||||||
public static DynamicProtobufSerializer Create(IEnumerable<Assembly> assemblies)
|
public static DynamicProtobufSerializer Create(IEnumerable<Type> types)
|
||||||
{
|
{
|
||||||
if (assemblies == null)
|
if (types == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("assemblies");
|
throw new ArgumentNullException("types");
|
||||||
}
|
}
|
||||||
|
|
||||||
var model = TypeModel.Create();
|
var model = TypeModel.Create();
|
||||||
var attributeType = typeof(ProtoContractAttribute);
|
var attributeType = typeof(ProtoContractAttribute);
|
||||||
|
|
||||||
// Find all ProtoContracts in the current assembly
|
// Find all ProtoContracts in the current assembly
|
||||||
foreach (var type in assemblies.SelectMany(a => MefUtils.GetTypes(a).Where(t => Attribute.IsDefined(t, attributeType))))
|
foreach (var type in types.Where(t => Attribute.IsDefined(t, attributeType)))
|
||||||
{
|
{
|
||||||
model.Add(type, true);
|
model.Add(type, true);
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,5 @@
|
|||||||
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.37" targetFramework="net45" />
|
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.37" targetFramework="net45" />
|
||||||
<package id="ServiceStack.Redis" version="3.9.37" targetFramework="net45" />
|
<package id="ServiceStack.Redis" version="3.9.37" targetFramework="net45" />
|
||||||
<package id="ServiceStack.Text" version="3.9.37" targetFramework="net45" />
|
<package id="ServiceStack.Text" version="3.9.37" targetFramework="net45" />
|
||||||
|
<package id="SimpleInjector" version="2.0.0-beta5" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
@ -1,5 +1,6 @@
|
|||||||
using MediaBrowser.Common.IO;
|
using MediaBrowser.Common.IO;
|
||||||
using MediaBrowser.Common.Kernel;
|
using MediaBrowser.Common.Kernel;
|
||||||
|
using MediaBrowser.Common.Localization;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Controller.Drawing;
|
using MediaBrowser.Controller.Drawing;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
@ -27,6 +28,7 @@ using System.ComponentModel.Composition.Hosting;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using SimpleInjector;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller
|
namespace MediaBrowser.Controller
|
||||||
{
|
{
|
||||||
@ -178,25 +180,29 @@ namespace MediaBrowser.Controller
|
|||||||
get { return KernelContext.Server; }
|
get { return KernelContext.Server; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of Localized string files
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The string files.</value>
|
||||||
|
[ImportMany(typeof(LocalizedStringData))]
|
||||||
|
public IEnumerable<LocalizedStringData> StringFiles { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of plugin configuration pages
|
/// Gets the list of plugin configuration pages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The configuration pages.</value>
|
/// <value>The configuration pages.</value>
|
||||||
[ImportMany(typeof(IPluginConfigurationPage))]
|
|
||||||
public IEnumerable<IPluginConfigurationPage> PluginConfigurationPages { get; private set; }
|
public IEnumerable<IPluginConfigurationPage> PluginConfigurationPages { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the intro providers.
|
/// Gets the intro providers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The intro providers.</value>
|
/// <value>The intro providers.</value>
|
||||||
[ImportMany(typeof(IIntroProvider))]
|
|
||||||
public IEnumerable<IIntroProvider> IntroProviders { get; private set; }
|
public IEnumerable<IIntroProvider> IntroProviders { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of currently registered weather prvoiders
|
/// Gets the list of currently registered weather prvoiders
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The weather providers.</value>
|
/// <value>The weather providers.</value>
|
||||||
[ImportMany(typeof(IWeatherProvider))]
|
|
||||||
public IEnumerable<IWeatherProvider> WeatherProviders { get; private set; }
|
public IEnumerable<IWeatherProvider> WeatherProviders { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -232,7 +238,6 @@ namespace MediaBrowser.Controller
|
|||||||
/// Gets the list of available user repositories
|
/// Gets the list of available user repositories
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The user repositories.</value>
|
/// <value>The user repositories.</value>
|
||||||
[ImportMany(typeof(IUserRepository))]
|
|
||||||
private IEnumerable<IUserRepository> UserRepositories { get; set; }
|
private IEnumerable<IUserRepository> UserRepositories { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -251,7 +256,6 @@ namespace MediaBrowser.Controller
|
|||||||
/// Gets the list of available item repositories
|
/// Gets the list of available item repositories
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The item repositories.</value>
|
/// <value>The item repositories.</value>
|
||||||
[ImportMany(typeof(IItemRepository))]
|
|
||||||
private IEnumerable<IItemRepository> ItemRepositories { get; set; }
|
private IEnumerable<IItemRepository> ItemRepositories { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -264,22 +268,19 @@ namespace MediaBrowser.Controller
|
|||||||
/// Gets the list of available item repositories
|
/// Gets the list of available item repositories
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The user data repositories.</value>
|
/// <value>The user data repositories.</value>
|
||||||
[ImportMany(typeof(IUserDataRepository))]
|
|
||||||
private IEnumerable<IUserDataRepository> UserDataRepositories { get; set; }
|
private IEnumerable<IUserDataRepository> UserDataRepositories { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of available DisplayPreferencesRepositories
|
/// Gets the list of available DisplayPreferencesRepositories
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The display preferences repositories.</value>
|
/// <value>The display preferences repositories.</value>
|
||||||
[ImportMany(typeof(IDisplayPreferencesRepository))]
|
|
||||||
private IEnumerable<IDisplayPreferencesRepository> DisplayPreferencesRepositories { get; set; }
|
private IEnumerable<IDisplayPreferencesRepository> DisplayPreferencesRepositories { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of entity resolution ignore rules
|
/// Gets the list of entity resolution ignore rules
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The entity resolution ignore rules.</value>
|
/// <value>The entity resolution ignore rules.</value>
|
||||||
[ImportMany(typeof(BaseResolutionIgnoreRule))]
|
internal IEnumerable<IResolutionIgnoreRule> EntityResolutionIgnoreRules { get; private set; }
|
||||||
internal IEnumerable<BaseResolutionIgnoreRule> EntityResolutionIgnoreRules { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the active user data repository
|
/// Gets the active user data repository
|
||||||
@ -357,12 +358,35 @@ namespace MediaBrowser.Controller
|
|||||||
/// Composes the exported values.
|
/// Composes the exported values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="container">The container.</param>
|
/// <param name="container">The container.</param>
|
||||||
protected override void ComposeExportedValues(CompositionContainer container)
|
/// <param name="iocContainer">The _ioc container.</param>
|
||||||
|
protected override void ComposeExportedValues(CompositionContainer container, Container iocContainer)
|
||||||
{
|
{
|
||||||
base.ComposeExportedValues(container);
|
base.ComposeExportedValues(container, iocContainer);
|
||||||
|
|
||||||
container.ComposeExportedValue("kernel", this);
|
container.ComposeExportedValue("kernel", this);
|
||||||
container.ComposeExportedValue("blurayExaminer", BlurayExaminer);
|
container.ComposeExportedValue("blurayExaminer", BlurayExaminer);
|
||||||
|
|
||||||
|
iocContainer.RegisterSingle(this);
|
||||||
|
iocContainer.RegisterSingle(BlurayExaminer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Composes the parts with ioc container.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="allTypes">All types.</param>
|
||||||
|
/// <param name="container">The container.</param>
|
||||||
|
protected override void ComposePartsWithIocContainer(Type[] allTypes, Container container)
|
||||||
|
{
|
||||||
|
base.ComposePartsWithIocContainer(allTypes, container);
|
||||||
|
|
||||||
|
EntityResolutionIgnoreRules = GetExports<IResolutionIgnoreRule>(allTypes);
|
||||||
|
UserDataRepositories = GetExports<IUserDataRepository>(allTypes);
|
||||||
|
UserRepositories = GetExports<IUserRepository>(allTypes);
|
||||||
|
DisplayPreferencesRepositories = GetExports<IDisplayPreferencesRepository>(allTypes);
|
||||||
|
ItemRepositories = GetExports<IItemRepository>(allTypes);
|
||||||
|
WeatherProviders = GetExports<IWeatherProvider>(allTypes);
|
||||||
|
IntroProviders = GetExports<IIntroProvider>(allTypes);
|
||||||
|
PluginConfigurationPages = GetExports<IPluginConfigurationPage>(allTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -63,6 +63,10 @@
|
|||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\packages\protobuf-net.2.0.0.621\lib\net40\protobuf-net.dll</HintPath>
|
<HintPath>..\packages\protobuf-net.2.0.0.621\lib\net40\protobuf-net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="SimpleInjector, Version=2.0.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\packages\SimpleInjector.2.0.0-beta5\lib\net40-client\SimpleInjector.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.ComponentModel.Composition" />
|
<Reference Include="System.ComponentModel.Composition" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
@ -165,7 +169,7 @@
|
|||||||
<Compile Include="Providers\MediaInfo\FFMpegVideoImageProvider.cs" />
|
<Compile Include="Providers\MediaInfo\FFMpegVideoImageProvider.cs" />
|
||||||
<Compile Include="Resolvers\Audio\MusicAlbumResolver.cs" />
|
<Compile Include="Resolvers\Audio\MusicAlbumResolver.cs" />
|
||||||
<Compile Include="Resolvers\Audio\MusicArtistResolver.cs" />
|
<Compile Include="Resolvers\Audio\MusicArtistResolver.cs" />
|
||||||
<Compile Include="Resolvers\BaseResolutionIgnoreRule.cs" />
|
<Compile Include="Resolvers\IResolutionIgnoreRule.cs" />
|
||||||
<Compile Include="Resolvers\CoreResolutionIgnoreRule.cs" />
|
<Compile Include="Resolvers\CoreResolutionIgnoreRule.cs" />
|
||||||
<Compile Include="Resolvers\EntityResolutionHelper.cs" />
|
<Compile Include="Resolvers\EntityResolutionHelper.cs" />
|
||||||
<Compile Include="Resolvers\LocalTrailerResolver.cs" />
|
<Compile Include="Resolvers\LocalTrailerResolver.cs" />
|
||||||
|
@ -9,8 +9,8 @@ namespace MediaBrowser.Controller.Resolvers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides the core resolver ignore rules
|
/// Provides the core resolver ignore rules
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Export(typeof(BaseResolutionIgnoreRule))]
|
[Export(typeof(IResolutionIgnoreRule))]
|
||||||
public class CoreResolutionIgnoreRule : BaseResolutionIgnoreRule
|
public class CoreResolutionIgnoreRule : IResolutionIgnoreRule
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Any folder named in this list will be ignored - can be added to at runtime for extensibility
|
/// Any folder named in this list will be ignored - can be added to at runtime for extensibility
|
||||||
@ -27,7 +27,7 @@ namespace MediaBrowser.Controller.Resolvers
|
|||||||
"extrafanart"
|
"extrafanart"
|
||||||
};
|
};
|
||||||
|
|
||||||
public override bool ShouldIgnore(ItemResolveArgs args)
|
public bool ShouldIgnore(ItemResolveArgs args)
|
||||||
{
|
{
|
||||||
// Ignore hidden files and folders
|
// Ignore hidden files and folders
|
||||||
if (args.IsHidden)
|
if (args.IsHidden)
|
||||||
|
@ -5,8 +5,8 @@ namespace MediaBrowser.Controller.Resolvers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a base "rule" that anyone can use to have paths ignored by the resolver
|
/// Provides a base "rule" that anyone can use to have paths ignored by the resolver
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BaseResolutionIgnoreRule
|
public interface IResolutionIgnoreRule
|
||||||
{
|
{
|
||||||
public abstract bool ShouldIgnore(ItemResolveArgs args);
|
bool ShouldIgnore(ItemResolveArgs args);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,4 +2,5 @@
|
|||||||
<packages>
|
<packages>
|
||||||
<package id="morelinq" version="1.0.15631-beta" targetFramework="net45" />
|
<package id="morelinq" version="1.0.15631-beta" targetFramework="net45" />
|
||||||
<package id="protobuf-net" version="2.0.0.621" targetFramework="net45" />
|
<package id="protobuf-net" version="2.0.0.621" targetFramework="net45" />
|
||||||
|
<package id="SimpleInjector" version="2.0.0-beta5" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
@ -36,7 +36,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.ComponentModel.Composition" />
|
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data.SQLite">
|
<Reference Include="System.Data.SQLite">
|
||||||
<HintPath>..\packages\System.Data.SQLite.1.0.84.0\lib\net45\System.Data.SQLite.dll</HintPath>
|
<HintPath>..\packages\System.Data.SQLite.1.0.84.0\lib\net45\System.Data.SQLite.dll</HintPath>
|
||||||
|
@ -5,7 +5,6 @@ using MediaBrowser.Model.Entities;
|
|||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Composition;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -16,7 +15,6 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class SQLiteDisplayPreferencesRepository
|
/// Class SQLiteDisplayPreferencesRepository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Export(typeof(IDisplayPreferencesRepository))]
|
|
||||||
class SQLiteDisplayPreferencesRepository : SqliteRepository, IDisplayPreferencesRepository
|
class SQLiteDisplayPreferencesRepository : SqliteRepository, IDisplayPreferencesRepository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -40,8 +38,7 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
[ImportingConstructor]
|
public SQLiteDisplayPreferencesRepository(ILogger logger)
|
||||||
protected SQLiteDisplayPreferencesRepository([Import("logger")] ILogger logger)
|
|
||||||
: base(logger)
|
: base(logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ using MediaBrowser.Controller.Persistence;
|
|||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Composition;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -16,7 +15,6 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class SQLiteItemRepository
|
/// Class SQLiteItemRepository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Export(typeof(IItemRepository))]
|
|
||||||
public class SQLiteItemRepository : SqliteRepository, IItemRepository
|
public class SQLiteItemRepository : SqliteRepository, IItemRepository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -45,8 +43,7 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
[ImportingConstructor]
|
public SQLiteItemRepository(ILogger logger)
|
||||||
protected SQLiteItemRepository([Import("logger")] ILogger logger)
|
|
||||||
: base(logger)
|
: base(logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ using MediaBrowser.Controller.Persistence;
|
|||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Composition;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -15,7 +14,6 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class SQLiteUserDataRepository
|
/// Class SQLiteUserDataRepository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Export(typeof(IUserDataRepository))]
|
|
||||||
public class SQLiteUserDataRepository : SqliteRepository, IUserDataRepository
|
public class SQLiteUserDataRepository : SqliteRepository, IUserDataRepository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -39,8 +37,7 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
[ImportingConstructor]
|
public SQLiteUserDataRepository(ILogger logger)
|
||||||
protected SQLiteUserDataRepository([Import("logger")] ILogger logger)
|
|
||||||
: base(logger)
|
: base(logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ using MediaBrowser.Controller.Entities;
|
|||||||
using MediaBrowser.Controller.Persistence;
|
using MediaBrowser.Controller.Persistence;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Composition;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -16,7 +15,6 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class SQLiteUserRepository
|
/// Class SQLiteUserRepository
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Export(typeof(IUserRepository))]
|
|
||||||
public class SQLiteUserRepository : SqliteRepository, IUserRepository
|
public class SQLiteUserRepository : SqliteRepository, IUserRepository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -40,8 +38,7 @@ namespace MediaBrowser.Server.Sqlite
|
|||||||
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
[ImportingConstructor]
|
public SQLiteUserRepository(ILogger logger)
|
||||||
protected SQLiteUserRepository([Import("logger")] ILogger logger)
|
|
||||||
: base(logger)
|
: base(logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user