Skip to content

Commit

Permalink
MVP: Replaced Ninject by TinyIoC.
Browse files Browse the repository at this point in the history
Mac: Updated project with TinyIoC changes and new namespace update by ReSharper (last check-in).

Related to issue #356.

git-svn-id: http://hamster-svn/svn/repos/base@683 765c1f7c-9fb8-954f-9ff8-dd0915cb3117
  • Loading branch information
animal committed Jan 21, 2013
1 parent 25a1305 commit 7cfe486
Show file tree
Hide file tree
Showing 33 changed files with 4,649 additions and 4,706 deletions.
116 changes: 73 additions & 43 deletions MPfm/branches/current/MPfm.MVP/Bootstrapper/Bootstrapper.cs
Expand Up @@ -16,49 +16,79 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using MPfm.MVP.Models;
using AutoMapper;
using MPfm.Sound.AudioFiles;
using Ninject;

namespace MPfm.MVP.Bootstrapper
{
/// <summary>
/// Singleton static class for bootstrapping the application.
/// Configures AutoMapper and Ninject.
/// </summary>
public static class Bootstrapper
{
/// <summary>
/// Instance of the Ninject StandardKernel.
/// </summary>
private static IKernel kernel;
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Timers;
using AutoMapper;
using TinyIoC;
using MPfm.Core;
using MPfm.Library;
using MPfm.MVP;
using MPfm.Player;
using MPfm.Sound;
using MPfm.Library.Gateway;
using MPfm.MVP.Services;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Presenters;
using MPfm.MVP.Helpers;
using MPfm.MVP.Services.Interfaces;
using MPfm.Sound.AudioFiles;
using MPfm.MVP.Models;

static LibraryModule module;

/// <summary>
/// Constructor for the Bootstrapper static class.
/// </summary>
static Bootstrapper()
{
// Create Ninject kernel
module = new LibraryModule();
kernel = new StandardKernel(module);

// Configure Automapper
Mapper.CreateMap<AudioFile, SongInformationEntity>();
}

/// <summary>
/// Returns the instance of the StandardKernel for resolving dependencies.
/// </summary>
/// <returns>StandardKernel</returns>
public static IKernel GetKernel()
{
return kernel;
}
}
namespace MPfm.MVP
{
/// <summary>
/// Singleton static class for bootstrapping the application.
/// Configures AutoMapper and Ninject.
/// </summary>
public static class Bootstrapper
{
/// <summary>
/// Constructor for the Bootstrapper static class.
/// </summary>
static Bootstrapper()
{
// Get IoC container
var container = TinyIoC.TinyIoCContainer.Current;

// Register services
//container.Register<IMPfmGateway, MPfmGateway>().UsingConstructor(() => new MPfmGateway(ConfigurationHelper.DatabaseFilePath));
container.Register<IMPfmGateway>(new MPfmGateway(ConfigurationHelper.DatabaseFilePath));
container.Register<IInitializationService, InitializationService>().AsSingleton();
container.Register<IPlayerService, PlayerService>().AsSingleton();
container.Register<ILibraryService, LibraryService>().AsSingleton();
container.Register<IAudioFileCacheService, AudioFileCacheService>().AsSingleton();
container.Register<IUpdateLibraryService, UpdateLibraryService>().AsSingleton();

// Register presenters
container.Register<ISplashPresenter, SplashPresenter>().AsSingleton();
container.Register<IMainPresenter, MainPresenter>().AsSingleton();
container.Register<IPlayerPresenter, PlayerPresenter>().AsSingleton();
container.Register<ISongBrowserPresenter, SongBrowserPresenter>().AsSingleton();
container.Register<ILibraryBrowserPresenter, LibraryBrowserPresenter>().AsSingleton();
container.Register<IUpdateLibraryPresenter, UpdateLibraryPresenter>().AsSingleton();
container.Register<IEffectsPresenter, EffectsPresenter>().AsSingleton();
container.Register<IPreferencesPresenter, PreferencesPresenter>().AsSingleton();
container.Register<IPlaylistPresenter, PlaylistPresenter>().AsSingleton();

// Configure Automapper
Mapper.CreateMap<AudioFile, SongInformationEntity>();
}

/// <summary>
/// Returns the IoC container.
/// </summary>
/// <returns>IoC container</returns>
public static TinyIoC.TinyIoCContainer GetContainer()
{
return TinyIoC.TinyIoCContainer.Current;
}
}
}

62 changes: 0 additions & 62 deletions MPfm/branches/current/MPfm.MVP/Bootstrapper/LibraryModule.cs

This file was deleted.

8 changes: 2 additions & 6 deletions MPfm/branches/current/MPfm.MVP/MPfm.MVP.csproj
Expand Up @@ -64,9 +64,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Ninject">
<HintPath>..\MPfm.Mac\Lib\Ninject.dll</HintPath>
</Reference>
<Reference Include="AutoMapper">
<HintPath>Lib\AutoMapper.dll</HintPath>
</Reference>
Expand All @@ -87,7 +84,6 @@
<Compile Include="Models\SongInformationEntity.cs" />
<Compile Include="Models\UpdateLibraryEntity.cs" />
<Compile Include="Bootstrapper\Bootstrapper.cs" />
<Compile Include="Bootstrapper\LibraryModule.cs" />
<Compile Include="Services\UpdateLibraryService.cs" />
<Compile Include="Services\Events\RefreshStatusEventArgs.cs" />
<Compile Include="Services\Events\ProcessEndedEventArgs.cs" />
Expand Down Expand Up @@ -155,11 +151,11 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\MPfm.Core\MPfm.Core.csproj">
<Project>{d536fde5-989e-4979-9b39-63621ae4a205}</Project>
<Project>{D536FDE5-989E-4979-9B39-63621AE4A205}</Project>
<Name>MPfm.Core</Name>
</ProjectReference>
<ProjectReference Include="..\MPfm.Library\MPfm.Library.csproj">
<Project>{2a62d229-d7fc-41da-b676-bb1371659bfb}</Project>
<Project>{2A62D229-D7FC-41DA-B676-BB1371659BFB}</Project>
<Name>MPfm.Library</Name>
</ProjectReference>
<ProjectReference Include="..\MPfm.Player\MPfm.Player.csproj">
Expand Down
1 change: 0 additions & 1 deletion MPfm/branches/current/MPfm.MVP/MPfm.MVP.iOS.csproj
Expand Up @@ -191,7 +191,6 @@
<Compile Include="Models\SongInformationEntity.cs" />
<Compile Include="Models\UpdateLibraryEntity.cs" />
<Compile Include="Bootstrapper\Bootstrapper.cs" />
<Compile Include="Bootstrapper\LibraryModule.cs" />
<Compile Include="Services\UpdateLibraryService.cs" />
<Compile Include="Services\Events\RefreshStatusEventArgs.cs" />
<Compile Include="Services\Events\ProcessEndedEventArgs.cs" />
Expand Down
32 changes: 17 additions & 15 deletions MPfm/branches/current/MPfm.MVP/NavigationManager.cs
Expand Up @@ -23,11 +23,11 @@
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Reflection;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;
using Ninject;
using Ninject.Parameters;
using System.Reflection;
using TinyMessenger;
using TinyIoC;
using MPfm.MVP.Views;
using MPfm.MVP.Presenters.Interfaces;

namespace MPfm.MVP
{
Expand All @@ -52,7 +52,7 @@ public virtual void Start()
{
CreateSplashWindow();
}

public virtual void CreateSplashWindow()
{
// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Expand All @@ -61,31 +61,33 @@ public virtual void CreateSplashWindow()
CreateMainWindow();
};
Action<IBaseView> onViewReady = (view) => {
splashPresenter = Bootstrapper.Bootstrapper.GetKernel().Get<ISplashPresenter>();
splashPresenter = Bootstrapper.GetContainer().Resolve<ISplashPresenter>();
splashPresenter.BindView((ISplashView)view);
splashPresenter.Initialize(onInitDone); // TODO: Should the presenter call NavMgr instead of using an action?
};
splashView = Bootstrapper.Bootstrapper.GetKernel().Get<ISplashView>(new ConstructorArgument("onViewReady", onViewReady));
splashView = Bootstrapper.GetContainer().Resolve<ISplashView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
splashView.OnViewDestroy = () => {
splashView = null;
splashPresenter = null;
};
}

public abstract ISplashView CreateSplashWindowInstance(Action<IBaseView> onViewReady);

public virtual void CreateMainWindow()
{
// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Action<IBaseView> onViewReady = (view) => {
mainPresenter = Bootstrapper.Bootstrapper.GetKernel().Get<IMainPresenter>();
mainPresenter = Bootstrapper.GetContainer().Resolve<IMainPresenter>();
mainPresenter.BindView((IMainView)view);
playerPresenter = Bootstrapper.Bootstrapper.GetKernel().Get<IPlayerPresenter>();
playerPresenter = Bootstrapper.GetContainer().Resolve<IPlayerPresenter>();
playerPresenter.BindView((IPlayerView)view);
libraryBrowserPresenter = Bootstrapper.Bootstrapper.GetKernel().Get<ILibraryBrowserPresenter>();
libraryBrowserPresenter = Bootstrapper.GetContainer().Resolve<ILibraryBrowserPresenter>();
libraryBrowserPresenter.BindView((ILibraryBrowserView)view);
songBrowserPresenter = Bootstrapper.Bootstrapper.GetKernel().Get<ISongBrowserPresenter>();
songBrowserPresenter = Bootstrapper.GetContainer().Resolve<ISongBrowserPresenter>();
songBrowserPresenter.BindView((ISongBrowserView)view);
};
mainView = Bootstrapper.Bootstrapper.GetKernel().Get<IMainView>(new ConstructorArgument("onViewReady", onViewReady));
mainView = Bootstrapper.GetContainer().Resolve<IMainView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
mainView.OnViewDestroy = () => {
mainView = null;
mainPresenter = null;
Expand All @@ -107,12 +109,12 @@ public virtual void CreatePreferencesWindow()

// The view invokes the OnViewReady action when the view is ready. This means the presenter can be created and bound to the view.
Action<IBaseView> onViewReady = (view) => {
preferencesPresenter = Bootstrapper.Bootstrapper.GetKernel().Get<IPreferencesPresenter>();
preferencesPresenter = Bootstrapper.GetContainer().Resolve<IPreferencesPresenter>();
preferencesPresenter.BindView((IPreferencesView)view);
};

// Create view and manage view destruction
preferencesView = Bootstrapper.Bootstrapper.GetKernel().Get<IPreferencesView>(new ConstructorArgument("onViewReady", onViewReady));
preferencesView = Bootstrapper.GetContainer().Resolve<IPreferencesView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
preferencesView.OnViewDestroy = () => {
preferencesView = null;
preferencesPresenter = null;
Expand Down
Expand Up @@ -18,13 +18,14 @@
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using MPfm.Core;
using MPfm.MVP.Config;
using MPfm.MVP.Helpers;
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Services.Interfaces;

namespace MPfm.MVP.Services
{
Expand Down
Expand Up @@ -29,7 +29,8 @@
using MPfm.MVP.Models;
using MPfm.MVP.Services.Events;
using MPfm.MVP.Services.Interfaces;
using MPfm.Sound.AudioFiles;
using MPfm.Sound.AudioFiles;
using System.Text.RegularExpressions;

#if (MACOSX || LINUX)
using Mono.Unix;
Expand Down

0 comments on commit 7cfe486

Please sign in to comment.