@@ -55,7 +55,7 @@ public FluentFillerApi<T> Setup(FillerSetup fillerSetupToUse)
5555 /// </summary>
5656 public T Create ( )
5757 {
58- T objectToFill = ( T ) CreateInstanceOfType ( typeof ( T ) , _setupManager . GetFor < T > ( ) ) ;
58+ T objectToFill = ( T ) CreateInstanceOfType ( typeof ( T ) , _setupManager . GetFor < T > ( ) , new HashStack < Type > ( ) ) ;
5959
6060 Fill ( objectToFill ) ;
6161
@@ -68,9 +68,10 @@ public T Create()
6868 /// </summary>
6969 public IEnumerable < T > Create ( int count )
7070 {
71+ var typeStack = new HashStack < Type > ( ) ;
7172 for ( int n = 0 ; n < count ; n ++ )
7273 {
73- T objectToFill = ( T ) CreateInstanceOfType ( typeof ( T ) , _setupManager . GetFor < T > ( ) ) ;
74+ T objectToFill = ( T ) CreateInstanceOfType ( typeof ( T ) , _setupManager . GetFor < T > ( ) , typeStack ) ;
7475 Fill ( objectToFill ) ;
7576 yield return objectToFill ;
7677 }
@@ -87,7 +88,7 @@ public T Fill(T instanceToFill)
8788 }
8889
8990
90- private object CreateInstanceOfType ( Type type , FillerSetupItem currentSetupItem )
91+ private object CreateInstanceOfType ( Type type , FillerSetupItem currentSetupItem , HashStack < Type > typeTracker )
9192 {
9293 List < object > constructorArgs = new List < object > ( ) ;
9394
@@ -104,7 +105,7 @@ private object CreateInstanceOfType(Type type, FillerSetupItem currentSetupItem)
104105 {
105106 foreach ( Type paramType in paramTypes )
106107 {
107- constructorArgs . Add ( GetFilledObject ( paramType , currentSetupItem ) ) ;
108+ constructorArgs . Add ( GetFilledObject ( paramType , currentSetupItem , typeTracker ) ) ;
108109 }
109110
110111 break ;
@@ -313,7 +314,7 @@ private object GetFilledPoco(Type type, FillerSetupItem currentSetupItem, HashSt
313314 }
314315 typeTracker . Push ( type ) ;
315316
316- object result = CreateInstanceOfType ( type , currentSetupItem ) ;
317+ object result = CreateInstanceOfType ( type , currentSetupItem , typeTracker ) ;
317318
318319 FillInternal ( result , typeTracker ) ;
319320
@@ -404,7 +405,7 @@ private object CreateInstanceOfInterfaceOrAbstractClass(Type interfaceType, Fill
404405 if ( setupItem . InterfaceToImplementation . ContainsKey ( interfaceType ) )
405406 {
406407 Type implType = setupItem . InterfaceToImplementation [ interfaceType ] ;
407- result = CreateInstanceOfType ( implType , setupItem ) ;
408+ result = CreateInstanceOfType ( implType , setupItem , typeTracker ) ;
408409 }
409410 else
410411 {
0 commit comments