MonodroidStockPortfolio/MonoStockPortfolio/Framework/IoCAttribute.cs

26 lines
798 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
{
2011-02-06 01:48:55 +00:00
public sealed override void OnGetValue(LocationInterceptionArgs args)
2010-12-19 20:34:20 +00:00
{
if (ServiceLocator.Context == null)
{
2011-02-06 01:48:55 +00:00
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);
2011-02-06 01:48:55 +00:00
if (instantiation != null)
2010-12-19 20:34:20 +00:00
{
args.SetNewValue(instantiation);
}
args.ProceedGetValue();
}
}
}