MonodroidStockPortfolio/MonoStockPortfolio/Framework/IoCAttribute.cs

26 lines
789 B
C#
Raw Normal View History

2010-12-19 20:34:20 +00:00
using Android.Content;
using PostSharp.Aspects;
2010-12-27 04:18:10 +00:00
namespace MonoStockPortfolio.Framework
2010-12-19 20:34:20 +00:00
{
public class IoCAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
if (ServiceLocator.Context == null)
{
var activityContext= (Context)args.Instance;
ServiceLocator.Context = activityContext.ApplicationContext.ApplicationContext;
}
2010-12-19 20:34:20 +00:00
var locationType = args.Location.LocationType;
var instantiation = ServiceLocator.Get(locationType);
2010-12-19 20:34:20 +00:00
if(instantiation != null)
{
args.SetNewValue(instantiation);
}
args.ProceedGetValue();
}
}
}