MonodroidStockPortfolio/MonoStockPortfolio/Framework/ServiceLocator.cs

38 lines
1.3 KiB
C#
Raw Normal View History

using System;
using Android.Content;
2011-01-03 02:00:10 +00:00
using MonoStockPortfolio.Core.Config;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Core.Services;
using MonoStockPortfolio.Core.StockData;
using TinyIoC;
namespace MonoStockPortfolio.Framework
{
public static class ServiceLocator
{
public static Context Context { get; set; }
private static TinyIoCContainer _container;
public static object Get(Type serviceType)
{
if (_container == null)
{
_container = RegisterTypes();
}
return _container.Resolve(serviceType);
}
private static TinyIoCContainer RegisterTypes()
{
var container = TinyIoCContainer.Current;
container.Register<Context>(Context);
container.Register<IStockDataProvider, YahooStockDataProvider>().AsMultiInstance();
container.Register<IPortfolioService, PortfolioService>().AsMultiInstance();
container.Register<IPortfolioRepository, AndroidSqlitePortfolioRepository>().AsMultiInstance();
2011-01-03 02:00:10 +00:00
container.Register<IConfigRepository, AndroidSqliteConfigRepository>().AsMultiInstance();
return container;
}
}
}