@@ -84,8 +84,7 @@ public MapperConfigurationSpecifier From(IEnumerable<Assembly> assemblies, Func<
8484
8585 ThrowIfInvalidAssembliesSupplied ( matchingAssemblies . Any ( ) , nullSupplied : false ) ;
8686
87- ApplyConfigurationsIn ( matchingAssemblies . SelectMany ( QueryConfigurationTypesIn ) ) ;
88- return this ;
87+ return ApplyConfigurationsIn ( matchingAssemblies . SelectMany ( QueryConfigurationTypesIn ) ) ;
8988 }
9089
9190 /// <summary>
@@ -101,12 +100,10 @@ public MapperConfigurationSpecifier From<TConfiguration>()
101100 where TConfiguration : MapperConfiguration , new ( )
102101 {
103102 ThrowIfConfigurationAlreadyApplied ( typeof ( TConfiguration ) ) ;
104- ThrowIfDependedOnConfigurationNotApplied ( typeof ( TConfiguration ) ) ;
105103
106- var configuration = new TConfiguration ( ) ;
104+ var configurationTypeChain = GetAllConfigurationTypesFor ( typeof ( TConfiguration ) ) ;
107105
108- Apply ( configuration ) ;
109- return this ;
106+ return ApplyConfigurationsIn ( configurationTypeChain ) ;
110107 }
111108
112109 private void ThrowIfConfigurationAlreadyApplied ( Type configurationType )
@@ -118,29 +115,17 @@ private void ThrowIfConfigurationAlreadyApplied(Type configurationType)
118115 }
119116 }
120117
121- private void ThrowIfDependedOnConfigurationNotApplied ( Type configurationType )
118+ private static IEnumerable < Type > GetAllConfigurationTypesFor ( Type configurationType )
122119 {
123- var dependedOnTypes = GetDependedOnConfigurationTypesFor ( configurationType ) ;
124-
125- if ( dependedOnTypes . None ( ) )
126- {
127- return ;
128- }
129-
130- var missingDependencies = dependedOnTypes
131- . Filter ( t => ! ConfigurationApplied ( t ) )
132- . ToArray ( ) ;
133-
134- if ( missingDependencies . None ( ) )
120+ foreach ( var dependedOnType in GetDependedOnConfigurationTypesFor ( configurationType ) )
135121 {
136- return ;
122+ foreach ( var nestedDependedOnType in GetAllConfigurationTypesFor ( dependedOnType ) )
123+ {
124+ yield return nestedDependedOnType ;
125+ }
137126 }
138127
139- var configurationTypeName = configurationType . GetFriendlyName ( ) ;
140- var dependencyNames = missingDependencies . Project ( d => d . GetFriendlyName ( ) ) . Join ( ", " ) ;
141-
142- throw new MappingConfigurationException (
143- $ "Configuration { configurationTypeName } must be registered after depended-on configuration(s) { dependencyNames } ") ;
128+ yield return configurationType ;
144129 }
145130
146131 private bool ConfigurationApplied ( Type configurationType )
@@ -158,12 +143,9 @@ private bool ConfigurationApplied(Type configurationType)
158143 /// to be registered.
159144 /// </returns>
160145 public MapperConfigurationSpecifier FromAssemblyOf < T > ( )
161- {
162- ApplyConfigurationsIn ( QueryConfigurationTypesIn ( typeof ( T ) . GetAssembly ( ) ) ) ;
163- return this ;
164- }
146+ => ApplyConfigurationsIn ( QueryConfigurationTypesIn ( typeof ( T ) . GetAssembly ( ) ) ) ;
165147
166- private void ApplyConfigurationsIn ( IEnumerable < Type > configurationTypes )
148+ private MapperConfigurationSpecifier ApplyConfigurationsIn ( IEnumerable < Type > configurationTypes )
167149 {
168150 var configurationData = configurationTypes
169151 . Select ( t => new ConfigurationData ( t ) )
@@ -172,7 +154,7 @@ private void ApplyConfigurationsIn(IEnumerable<Type> configurationTypes)
172154 if ( configurationData . None ( d => d . DependedOnConfigurationTypes . Any ( ) ) )
173155 {
174156 Apply ( configurationData . Project ( d => d . Configuration ) ) ;
175- return ;
157+ return this ;
176158 }
177159
178160 var configurationCount = configurationData . Count ;
@@ -213,6 +195,7 @@ private void ApplyConfigurationsIn(IEnumerable<Type> configurationTypes)
213195 . Project ( kvp => configurationDataByType [ kvp . Key ] . Configuration ) ;
214196
215197 Apply ( orderedConfigurations ) ;
198+ return this ;
216199 }
217200
218201 private static void InsertWithOrder (
0 commit comments