diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-19 17:56:11 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-19 17:56:11 +0300 |
| commit | 3fe33a685c3ca7a8730dacffa5357f77d7e76a96 (patch) | |
| tree | bbdb2e455ab851e6b350ec98d8eacf8eb5f3fafc /Software/Visual_Studio/Tango.Core/DI | |
| parent | 425a679e42f0b61f2f63d92955600cadbc698e1d (diff) | |
| download | Tango-3fe33a685c3ca7a8730dacffa5357f77d7e76a96.tar.gz Tango-3fe33a685c3ca7a8730dacffa5357f77d7e76a96.zip | |
Implemented sample dye navigation on PPC.
Fixed some issues with TangoIOC GetWhenAvailable.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/DI')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs b/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs index e79a89acd..50b892552 100644 --- a/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs +++ b/Software/Visual_Studio/Tango.Core/DI/TangoIOC.cs @@ -72,7 +72,7 @@ namespace Tango.Core.DI /// <param name="instance">The instance.</param> public void Register<T>(T instance) where T : class { - RegisterInternal(typeof(T), typeof(T), instance); + RegisterInternal(typeof(T), instance.GetType(), instance); } /// <summary> @@ -154,6 +154,17 @@ namespace Tango.Core.DI } /// <summary> + /// Notifies the awaiting retrievals of a new instance available. + /// </summary> + /// <param name="registeredType">Type of the registered.</param> + private void NotifyAwaitingRetrievals(RegisteredType registeredType) + { + var toNotify = _waitingRetrivals.Where(x => x.Item1 == registeredType.InterfaceType).ToList(); + toNotify.ForEach(x => x.Item2(registeredType.Instance)); + _waitingRetrivals.RemoveAll(x => toNotify.Contains(x)); + } + + /// <summary> /// Gets the instance by the specified type. /// </summary> /// <param name="type">The type.</param> @@ -168,11 +179,7 @@ namespace Tango.Core.DI if (registeredType.Instance == null) { registeredType.Instance = CreateInstance(registeredType.ImplementationType); - - //Notify waiting retrievals. - var toNotify = _waitingRetrivals.Where(x => x.Item1 == registeredType.InterfaceType).ToList(); - toNotify.ForEach(x => x.Item2(registeredType.Instance)); - _waitingRetrivals.RemoveAll(x => toNotify.Contains(x)); + NotifyAwaitingRetrievals(registeredType); } return registeredType.Instance; @@ -269,7 +276,14 @@ namespace Tango.Core.DI throw new InvalidOperationException(String.Format("Instance type '{0}' does not match the implementation type '{1}'.", instance.GetType().Name, implementationType.Name)); } - _registeredTypes.Add(interfaceType, new RegisteredType(interfaceType, implementationType, instance)); + + var registeredType = new RegisteredType(interfaceType, implementationType, instance); + _registeredTypes.Add(interfaceType, registeredType); + + if (registeredType.Instance != null) + { + NotifyAwaitingRetrievals(registeredType); + } } /// <summary> |
