aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.UI/App.xaml.cs
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-02-23 02:57:11 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-02-23 02:57:11 -0500
commitb8d5c718429f1325111834b8b95698fc9c9ba47d (patch)
treef7f23b8704380552f25f3edfa3d706455069692e /MediaBrowser.UI/App.xaml.cs
parentc165f37bb96ad40d863a436795c21b9085f3fde9 (diff)
type discovery without attributes
Diffstat (limited to 'MediaBrowser.UI/App.xaml.cs')
-rw-r--r--MediaBrowser.UI/App.xaml.cs96
1 files changed, 85 insertions, 11 deletions
diff --git a/MediaBrowser.UI/App.xaml.cs b/MediaBrowser.UI/App.xaml.cs
index b98ce8e6c..bcaa0529e 100644
--- a/MediaBrowser.UI/App.xaml.cs
+++ b/MediaBrowser.UI/App.xaml.cs
@@ -118,6 +118,17 @@ namespace MediaBrowser.UI
}
/// <summary>
+ /// The container
+ /// </summary>
+ private SimpleInjector.Container _container = new SimpleInjector.Container();
+
+ /// <summary>
+ /// Gets or sets the iso manager.
+ /// </summary>
+ /// <value>The iso manager.</value>
+ private IIsoManager IsoManager { get; set; }
+
+ /// <summary>
/// Gets the instance.
/// </summary>
/// <value>The instance.</value>
@@ -290,15 +301,6 @@ namespace MediaBrowser.UI
InitializeComponent();
}
-
- /// <summary>
- /// Instantiates the kernel.
- /// </summary>
- /// <returns>IKernel.</returns>
- protected IKernel InstantiateKernel()
- {
- return new UIKernel(this, new PismoIsoManager(Logger), Logger);
- }
/// <summary>
/// Instantiates the main window.
@@ -405,7 +407,9 @@ namespace MediaBrowser.UI
// Without this the app will shutdown after the splash screen closes
ShutdownMode = ShutdownMode.OnExplicitShutdown;
- Kernel = InstantiateKernel();
+ RegisterResources();
+
+ Kernel = new UIKernel(this, Logger);
try
{
@@ -614,7 +618,8 @@ namespace MediaBrowser.UI
{
try
{
- ServerConfiguration = await ApiClient.GetServerConfigurationAsync();
+ var b = Kernel;
+ //ServerConfiguration = await ApiClient.GetServerConfigurationAsync();
}
catch (HttpException ex)
{
@@ -1011,6 +1016,19 @@ namespace MediaBrowser.UI
}
/// <summary>
+ /// Registers resources that classes will depend on
+ /// </summary>
+ private void RegisterResources()
+ {
+ Register<IApplicationHost>(this);
+ Register(Logger);
+
+ IsoManager = new PismoIsoManager(Logger);
+
+ Register<IIsoManager>(IsoManager);
+ }
+
+ /// <summary>
/// Updates the application.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
@@ -1020,5 +1038,61 @@ namespace MediaBrowser.UI
{
return new ApplicationUpdater().UpdateApplication(cancellationToken, progress);
}
+
+ /// <summary>
+ /// Creates an instance of type and resolves all constructor dependancies
+ /// </summary>
+ /// <param name="type">The type.</param>
+ /// <returns>System.Object.</returns>
+ public object CreateInstance(Type type)
+ {
+ try
+ {
+ return _container.GetInstance(type);
+ }
+ catch
+ {
+ Logger.Error("Error creating {0}", type.Name);
+
+ throw;
+ }
+ }
+
+ /// <summary>
+ /// Registers the specified obj.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="obj">The obj.</param>
+ public void Register<T>(T obj)
+ where T : class
+ {
+ _container.RegisterSingle(obj);
+ }
+
+ /// <summary>
+ /// Resolves this instance.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns>``0.</returns>
+ public T Resolve<T>()
+ {
+ return (T)_container.GetRegistration(typeof(T), true).GetInstance();
+ }
+
+ /// <summary>
+ /// Resolves this instance.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns>``0.</returns>
+ public T TryResolve<T>()
+ {
+ var result = _container.GetRegistration(typeof(T), false);
+
+ if (result == null)
+ {
+ return default(T);
+ }
+ return (T)result.GetInstance();
+ }
}
}