SmartDIExtensions.cs
/// <summary>
/// Attempts to resolve, and on failure, registers and tries again.
/// Might still return null, so must be checked after the call against default{classT}.
/// </summary>
/// <typeparam name="classT">The type of the class t.</typeparam>
/// <typeparam name="interfaceT">The type of the interface t.</typeparam>
/// <param name="diContainer">The di container.</param>
/// <param name="storageRule">The storage rule.</param>
/// <param name="boundInstance">The bound instance.</param>
/// <param name="creator">The creator.</param>
/// <param name="conflictResolver">The conflict resolver.</param>
/// <returns>interfaceT.</returns>
/// <summary>
/// Registers the and resolve as interface.
/// </summary>
/// <typeparam name="classT">The type of the class t.</typeparam>
/// <typeparam name="interfaceT">The type of the interface t.</typeparam>
/// <param name="diContainer">The di container.</param>
/// <param name="storageRule">The storage rule.</param>
/// <param name="boundInstance">The bound instance.</param>
/// <param name="creator">The creator.</param>
/// <param name="conflictResolver">The conflict resolver.</param>
/// <returns>interfaceT.</returns>
/// <autogeneratedoc />
/// TODO Edit XML Comment Template for RegisterAndResolveAsInterface`2
Registers the and resolve as interface.
Registers the and resolve as interface .
public static interfaceT RegisterAndResolveAsInterface<classT, interfaceT>
      (
         this ISmartDIContainer diContainer,
         StorageRules storageRule =
            StorageRules.AnyAccessLevel,
         object                                                                           boundInstance    = null,
         Func<object>                                                                     creator          = null,
         Func<IDictionary<Type, ITimeStampedCreatorAndStorageRules>, IConflictResolution> conflictResolver = null
      )
         where classT : class, interfaceT
         where interfaceT : class
      {
         var triedOnce = false;
      TRYAGAIN:
         diContainer.IgnoreResolveError = true;
         var possibleT = diContainer.Resolve<interfaceT>(storageRule, boundInstance, conflictResolver);
         diContainer.IgnoreResolveError = false;
         if (possibleT.IsNotAnEqualObjectTo(default(classT)))
         {
            return possibleT;
         }
         if (triedOnce)
         {
            return default(classT);
         }
         RegisterTypeAsInterface<classT>(diContainer, typeof(interfaceT), storageRule, creator);
         triedOnce = true;
         goto TRYAGAIN;
      }
public static interfaceT RegisterAndResolveAsInterface < classT , interfaceT > ( this ISmartDIContainer diContainer , StorageRules storageRule = StorageRules . AnyAccessLevel , object boundInstance = null , Func < object > creator = null , Func < IDictionary < Type , ITimeStampedCreatorAndStorageRules > , IConflictResolution > conflictResolver = null ) where classT : class , interfaceT where interfaceT : class { var triedOnce = false ; TRYAGAIN : diContainer . IgnoreResolveError = true ; var possibleT = diContainer . Resolve < interfaceT > ( storageRule , boundInstance , conflictResolver ) ; diContainer . IgnoreResolveError = false ; if ( possibleT . IsNotAnEqualObjectTo ( default ( classT ) ) ) { return possibleT ; } if ( triedOnce ) { return default ( classT ) ; } RegisterTypeAsInterface < classT > ( diContainer , typeof ( interfaceT ) , storageRule , creator ) ; triedOnce = true ; goto TRYAGAIN ; }
Registers the and resolve as interface.
Registers the and resolve as interface .
// Prevents thrown errors temporarily // Resolves INTERFACE // No reason to keep trying // ELSE Register and try again
None
None
ISmartDIContainer
this
storageRule
StorageRules
The storage rule.
The storage rule .
boundInstance
object
The bound instance.
The bound instance .
creator
Func<object>
None
conflictResolver
Func<IDictionary<Type, ITimeStampedCreatorAndStorageRules>, IConflictResolution>
The conflict resolver.
The conflict resolver .
diContainer
The di container.
The di container .
typeparam
The type of the class t.
The type of the class t .
typeparam
The type of the interface t.
The type of the interface t .
typeparam
The type of the class t.
The type of the class t .
typeparam
The type of the interface t.
The type of the interface t .
autogeneratedoc
None