MonodroidStockPortfolio/MonoStockPortfolio/Framework/IoCAttribute.cs
2011-02-05 20:48:55 -05:00

26 lines
No EOL
798 B
C#

using Android.Content;
using PostSharp.Aspects;
namespace MonoStockPortfolio.Framework
{
public class IoCAttribute : LocationInterceptionAspect
{
public sealed override void OnGetValue(LocationInterceptionArgs args)
{
if (ServiceLocator.Context == null)
{
var activityContext = (Context)args.Instance;
ServiceLocator.Context = activityContext.ApplicationContext.ApplicationContext;
}
var locationType = args.Location.LocationType;
var instantiation = ServiceLocator.Get(locationType);
if (instantiation != null)
{
args.SetNewValue(instantiation);
}
args.ProceedGetValue();
}
}
}