diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
index e2ef4864d0..f63108048e 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
@@ -35,7 +35,7 @@ namespace MediaBrowser.Common.Implementations
/// Class BaseApplicationHost
///
/// The type of the T application paths type.
- public abstract class BaseApplicationHost : IApplicationHost
+ public abstract class BaseApplicationHost : IApplicationHost, IDependencyContainer
where TApplicationPathsType : class, IApplicationPaths
{
///
@@ -406,9 +406,30 @@ namespace MediaBrowser.Common.Implementations
IsoManager = new IsoManager();
RegisterSingleInstance(IsoManager);
+
+ RegisterModules();
});
}
+ private void RegisterModules()
+ {
+ var moduleTypes = GetExportTypes();
+
+ foreach (var type in moduleTypes)
+ {
+ try
+ {
+ var instance = Activator.CreateInstance(type) as IDependencyModule;
+ if (instance != null)
+ instance.BindDependencies(this);
+ }
+ catch (Exception ex)
+ {
+ Logger.ErrorException("Error setting up dependency bindings for " + type.Name, ex);
+ }
+ }
+ }
+
protected virtual IFileSystem CreateFileSystemManager()
{
return new CommonFileSystem(Logger, true);
@@ -479,6 +500,11 @@ namespace MediaBrowser.Common.Implementations
}
}
+ void IDependencyContainer.RegisterSingleInstance(T obj, bool manageLifetime)
+ {
+ RegisterSingleInstance(obj, manageLifetime);
+ }
+
///
/// Registers the specified obj.
///
@@ -501,6 +527,11 @@ namespace MediaBrowser.Common.Implementations
}
}
+ void IDependencyContainer.RegisterSingleInstance(Func func)
+ {
+ RegisterSingleInstance(func);
+ }
+
///
/// Registers the single instance.
///
@@ -512,6 +543,11 @@ namespace MediaBrowser.Common.Implementations
Container.RegisterSingle(func);
}
+ void IDependencyContainer.Register(Type typeInterface, Type typeImplementation)
+ {
+ Container.Register(typeInterface, typeImplementation);
+ }
+
///
/// Resolves this instance.
///
diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs
index 3d5f3c96f9..fb49cc5b95 100644
--- a/MediaBrowser.Common/IApplicationHost.cs
+++ b/MediaBrowser.Common/IApplicationHost.cs
@@ -152,4 +152,15 @@ namespace MediaBrowser.Common
/// System.Object.
object CreateInstance(Type type);
}
+
+ public interface IDependencyContainer
+ {
+ void RegisterSingleInstance(T obj, bool manageLifetime = true)
+ where T : class;
+
+ void RegisterSingleInstance(Func func)
+ where T : class;
+
+ void Register(Type typeInterface, Type typeImplementation);
+ }
}
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index 63819c5a93..5e0d3aa245 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -79,6 +79,7 @@
+
diff --git a/MediaBrowser.Common/Plugins/IDependencyModule.cs b/MediaBrowser.Common/Plugins/IDependencyModule.cs
new file mode 100644
index 0000000000..37ebe0d5b2
--- /dev/null
+++ b/MediaBrowser.Common/Plugins/IDependencyModule.cs
@@ -0,0 +1,7 @@
+namespace MediaBrowser.Common.Plugins
+{
+ public interface IDependencyModule
+ {
+ void BindDependencies(IDependencyContainer container);
+ }
+}
\ No newline at end of file