aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core/DI
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-07-15 14:16:26 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-07-15 14:16:26 +0300
commitde5700549a5fe01862f71d452f2abe4a74996605 (patch)
treed64cd490c7012ea96299ea891d5d7013a822e347 /Software/Visual_Studio/Tango.Core/DI
parentc6b01f3e683b83fb0d6bf080efbd24a9a732b9f5 (diff)
downloadTango-de5700549a5fe01862f71d452f2abe4a74996605.tar.gz
Tango-de5700549a5fe01862f71d452f2abe4a74996605.zip
Implemented PPC twine animated gif.
Sign out. Implemented TangoInject attribute 'When Available' mode!
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/DI')
-rw-r--r--Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs28
-rw-r--r--Software/Visual_Studio/Tango.Core/DI/TangoInjectAttribute.cs10
-rw-r--r--Software/Visual_Studio/Tango.Core/DI/TangoInjectMode.cs14
3 files changed, 50 insertions, 2 deletions
diff --git a/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs b/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs
index 20827bca7..e79a89acd 100644
--- a/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs
+++ b/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs
@@ -341,12 +341,36 @@ namespace Tango.Core.DI
foreach (var prop in type.GetPropertiesWithAttribute<TangoInjectAttribute>(BindingFlags.Public | BindingFlags.Instance))
{
- prop.SetValue(target, GetInstance(prop.PropertyType));
+ var att = prop.GetCustomAttribute<TangoInjectAttribute>();
+
+ if (att.Mode == TangoInjectMode.Immediate)
+ {
+ prop.SetValue(target, GetInstance(prop.PropertyType));
+ }
+ else
+ {
+ GetInstanceWhenAvailable(prop.PropertyType, (x) =>
+ {
+ prop.SetValue(target, GetInstance(prop.PropertyType));
+ });
+ }
}
foreach (var field in type.GetFieldsWithAttribute<TangoInjectAttribute>(BindingFlags.NonPublic | BindingFlags.Instance))
{
- field.SetValue(target, GetInstance(field.FieldType));
+ var att = field.GetCustomAttribute<TangoInjectAttribute>();
+
+ if (att.Mode == TangoInjectMode.Immediate)
+ {
+ field.SetValue(target, GetInstance(field.FieldType));
+ }
+ else
+ {
+ GetInstanceWhenAvailable(field.FieldType, (x) =>
+ {
+ field.SetValue(target, GetInstance(field.FieldType));
+ });
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.Core/DI/TangoInjectAttribute.cs b/Software/Visual_Studio/Tango.Core/DI/TangoInjectAttribute.cs
index f316347fb..b05a83769 100644
--- a/Software/Visual_Studio/Tango.Core/DI/TangoInjectAttribute.cs
+++ b/Software/Visual_Studio/Tango.Core/DI/TangoInjectAttribute.cs
@@ -9,6 +9,16 @@ namespace Tango.Core.DI
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Constructor)]
public class TangoInjectAttribute : Attribute
{
+ public TangoInjectMode Mode { get; set; }
+ public TangoInjectAttribute()
+ {
+
+ }
+
+ public TangoInjectAttribute(TangoInjectMode mode)
+ {
+ Mode = mode;
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.Core/DI/TangoInjectMode.cs b/Software/Visual_Studio/Tango.Core/DI/TangoInjectMode.cs
new file mode 100644
index 000000000..7ee70b3ec
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Core/DI/TangoInjectMode.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Core.DI
+{
+ public enum TangoInjectMode
+ {
+ Immediate,
+ WhenAvailable,
+ }
+}