diff options
| author | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
|---|---|---|
| committer | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
| commit | 00a491d93733d4625ad329b2ba8237f445364b3f (patch) | |
| tree | 4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.Core/DI | |
| parent | 124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff) | |
| download | Tango-00a491d9.tar.gz Tango-00a491d9.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/DI')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs | 44 |
1 files changed, 3 insertions, 41 deletions
diff --git a/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs b/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs index 19e1e91bc..de42ac6e7 100644 --- a/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs +++ b/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs @@ -48,11 +48,6 @@ namespace Tango.Core.DI private List<Tuple<Type, Action<Object>>> _waitingRetrivals; /// <summary> - /// Gets or sets a value indicating whether to throw an exception when a type is requested but not registered. - /// </summary> - public bool ThrowOnRequestedTypeNotFound { get; set; } = true; - - /// <summary> /// Initializes a new instance of the <see cref="TangoIOC"/> class. /// </summary> public TangoIOC() @@ -191,21 +186,7 @@ namespace Tango.Core.DI } else { - //Try get by inherited.. - registeredType = _registeredTypes.Select(x => x.Value).SingleOrDefault(x => type.IsAssignableFrom(x.InterfaceType)); - - if (registeredType != null) - { - if (registeredType.Instance == null) - { - registeredType.Instance = CreateInstance(registeredType.ImplementationType); - NotifyAwaitingRetrievals(registeredType); - } - - return registeredType.Instance; - } - - if (!DesignMode && ThrowOnRequestedTypeNotFound) + if (!DesignMode) { throw new InvalidOperationException(String.Format("Requested type '{0}' could not be found.", type.Name)); } @@ -244,20 +225,6 @@ namespace Tango.Core.DI return; } } - else - { - //Try get by inherited.. - registeredType = _registeredTypes.Select(x => x.Value).SingleOrDefault(x => type.IsAssignableFrom(x.InterfaceType)); - - if (registeredType != null) - { - if (registeredType.Instance != null) - { - callback(registeredType.Instance); - return; - } - } - } _waitingRetrivals.Add(new Tuple<Type, Action<object>>(type, callback)); } @@ -294,11 +261,6 @@ namespace Tango.Core.DI /// <param name="instance">The instance.</param> protected virtual void RegisterInternal(Type interfaceType, Type implementationType, Object instance) { - if (DesignMode) - { - return; - } - if (!interfaceType.IsAssignableFrom(implementationType)) { throw new InvalidOperationException(String.Format("Interface type '{0}' cannot be assigned from implementation type '{1}'.", interfaceType.Name, implementationType.Name)); @@ -385,7 +347,7 @@ namespace Tango.Core.DI /// <returns></returns> public virtual IEnumerable<object> GetAllInstancesByBase(Type baseType) { - return _registeredTypes.Where(x => baseType.IsAssignableFrom(x.Key)).Select(x => x.Value.Instance != null ? x.Value.Instance : GetInstance(x.Value.ImplementationType)); + return _registeredTypes.Where(x => baseType.IsAssignableFrom(x.Key)).Select(x => x.Value.Instance != null ? x.Value.Instance : CreateInstance(x.Value.ImplementationType)); } /// <summary> @@ -396,7 +358,7 @@ namespace Tango.Core.DI { var type = target.GetType(); - foreach (var prop in type.GetPropertiesWithAttribute<TangoInjectAttribute>(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)) + foreach (var prop in type.GetPropertiesWithAttribute<TangoInjectAttribute>(BindingFlags.Public | BindingFlags.Instance)) { var att = prop.GetCustomAttribute<TangoInjectAttribute>(); |
