MonodroidStockPortfolio/MonoStockPortfolio/Framework/ServiceLocator.cs

50 lines
1.9 KiB
C#
Raw Normal View History

using System;
using Android.Content;
using Android.Util;
using MonoStockPortfolio.Activites.ConfigScreen;
using MonoStockPortfolio.Activites.EditPortfolioScreen;
using MonoStockPortfolio.Activites.EditPositionScreen;
using MonoStockPortfolio.Activites.MainScreen;
using MonoStockPortfolio.Activites.PortfolioScreen;
2011-01-03 02:00:10 +00:00
using MonoStockPortfolio.Core.Config;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Core.Services;
using MonoStockPortfolio.Core.StockData;
namespace MonoStockPortfolio.Framework
{
public static class ServiceLocator
{
public static Context Context { get; set; }
2011-02-06 01:48:55 +00:00
static ServiceLocator()
{
// services/repositories
IttyBittyIoC.Register<Context>(() => Context);
IttyBittyIoC.Register<IStockDataProvider, YahooStockDataProvider>();
IttyBittyIoC.Register<IPortfolioRepository,AndroidSqlitePortfolioRepository>();
IttyBittyIoC.Register<IPortfolioService, PortfolioService>();
IttyBittyIoC.Register<IConfigRepository, AndroidSqliteConfigRepository>();
// presenters
IttyBittyIoC.Register<IMainPresenter, MainPresenter>();
IttyBittyIoC.Register<IPortfolioPresenter, PortfolioPresenter>();
IttyBittyIoC.Register<IEditPortfolioPresenter, EditPortfolioPresenter>();
IttyBittyIoC.Register<IEditPositionPresenter, EditPositionPresenter>();
IttyBittyIoC.Register<IConfigPresenter, ConfigPresenter>();
}
2011-02-06 01:48:55 +00:00
public static object Get(Type serviceType)
{
try
{
return IttyBittyIoC.Resolve(serviceType);
}
catch (Exception)
{
Log.Error("ServiceLocatorGet", "Unable to resolve type: " + serviceType.Name);
throw;
}
}
}
}