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
|
|
|
{
|
2011-01-02 22:27:28 +00:00
|
|
|
if (ServiceLocator.Context == null)
|
2010-12-27 02:47:10 +00:00
|
|
|
{
|
2011-02-06 01:48:55 +00:00
|
|
|
var activityContext = (Context)args.Instance;
|
2011-01-02 22:27:28 +00:00
|
|
|
ServiceLocator.Context = activityContext.ApplicationContext.ApplicationContext;
|
2011-01-02 22:10:27 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 20:34:20 +00:00
|
|
|
var locationType = args.Location.LocationType;
|
2011-01-02 22:27:28 +00:00
|
|
|
var instantiation = ServiceLocator.Get(locationType);
|
2011-01-02 22:10:27 +00:00
|
|
|
|
2011-02-06 01:48:55 +00:00
|
|
|
if (instantiation != null)
|
2010-12-19 20:34:20 +00:00
|
|
|
{
|
|
|
|
args.SetNewValue(instantiation);
|
|
|
|
}
|
|
|
|
args.ProceedGetValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|