1- // Copyright (C) 2009-2020 Xtensive LLC.
1+ // Copyright (C) 2009-2021 Xtensive LLC.
22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44// Created by: Dmitri Maximov
1515using Xtensive . IoC . Configuration ;
1616using AttributeSearchOptions = Xtensive . Reflection . AttributeSearchOptions ;
1717using AppConfiguration = System . Configuration . Configuration ;
18- using ConfigurationSection = Xtensive . IoC . Configuration . ConfigurationSection ;
18+ using ConfigurationSection = Xtensive . IoC . Configuration . ConfigurationSection ;
1919
2020namespace Xtensive . IoC
2121{
@@ -25,11 +25,11 @@ namespace Xtensive.IoC
2525 [ Serializable ]
2626 public class ServiceContainer : ServiceContainerBase
2727 {
28- private readonly Dictionary < object , List < ServiceRegistration > > types =
28+ private readonly Dictionary < object , List < ServiceRegistration > > types =
2929 new Dictionary < object , List < ServiceRegistration > > ( ) ;
30- private readonly Dictionary < ServiceRegistration , object > instances =
30+ private readonly Dictionary < ServiceRegistration , object > instances =
3131 new Dictionary < ServiceRegistration , object > ( ) ;
32- private readonly Dictionary < ServiceRegistration , Pair < ConstructorInfo , ParameterInfo [ ] > > constructorCache =
32+ private readonly Dictionary < ServiceRegistration , Pair < ConstructorInfo , ParameterInfo [ ] > > constructorCache =
3333 new Dictionary < ServiceRegistration , Pair < ConstructorInfo , ParameterInfo [ ] > > ( ) ;
3434 private readonly HashSet < Type > creating = new HashSet < Type > ( ) ;
3535 private readonly object _lock = new object ( ) ;
@@ -45,7 +45,7 @@ protected override object HandleGet(Type serviceType, string name)
4545 List < ServiceRegistration > list ;
4646 if ( ! types . TryGetValue ( GetKey ( serviceType , name ) , out list ) )
4747 return null ;
48- if ( list . Count == 0 )
48+ if ( list . Count == 0 )
4949 return null ;
5050 if ( list . Count > 1 )
5151 throw new AmbiguousMatchException ( Strings . ExMultipleServicesMatchToTheSpecifiedArguments ) ;
@@ -75,25 +75,25 @@ protected virtual object CreateInstance(ServiceRegistration serviceInfo)
7575 {
7676 if ( creating . Contains ( serviceInfo . Type ) )
7777 throw new ActivationException ( Strings . ExRecursiveConstructorParemeterDependencyIsDetected ) ;
78- Pair < ConstructorInfo , ParameterInfo [ ] > cachedInfo ;
78+ Pair < ConstructorInfo , ParameterInfo [ ] > cachedInfo ;
7979 var mappedType = serviceInfo . MappedType ;
8080 if ( ! constructorCache . TryGetValue ( serviceInfo , out cachedInfo ) ) {
8181 var @ctor = (
8282 from c in mappedType . GetConstructors ( )
83- where c . GetAttribute < ServiceConstructorAttribute > ( AttributeSearchOptions . InheritNone ) != null
83+ where c . GetAttribute < ServiceConstructorAttribute > ( AttributeSearchOptions . InheritNone ) != null
8484 select c
8585 ) . SingleOrDefault ( ) ;
86- if ( @ctor == null )
86+ if ( @ctor == null )
8787 @ctor = mappedType . GetConstructor ( ArrayUtils < Type > . EmptyArray ) ;
88- var @params = @ctor == null ? null : @ctor . GetParameters ( ) ;
88+ var @params = @ctor == null ? null : @ctor . GetParameters ( ) ;
8989 cachedInfo = new Pair < ConstructorInfo , ParameterInfo [ ] > ( @ctor , @params ) ;
9090 constructorCache [ serviceInfo ] = cachedInfo ;
9191 }
9292 var cInfo = cachedInfo . First ;
93- if ( cInfo == null )
93+ if ( cInfo == null )
9494 return null ;
9595 var pInfos = cachedInfo . Second ;
96- if ( pInfos . Length == 0 )
96+ if ( pInfos . Length == 0 )
9797 return Activator . CreateInstance ( mappedType ) ;
9898 var args = new object [ pInfos . Length ] ;
9999 creating . Add ( serviceInfo . Type ) ;
@@ -128,7 +128,7 @@ private IEnumerable<object> GetOrCreateInstances(IEnumerable<ServiceRegistration
128128 continue ;
129129 }
130130
131- if ( registration . MappedInstance != null )
131+ if ( registration . MappedInstance != null )
132132 result = registration . MappedInstance ;
133133 else
134134 result = CreateInstance ( registration ) ;
@@ -207,12 +207,12 @@ public static IServiceContainer Create(Type containerType, object configuration,
207207
208208 var possibleArgs =
209209 Enumerable . Empty < object [ ] > ( )
210- . Append ( new [ ] { configuration , parent } )
211- . Append ( new [ ] { configuration } )
212- . Append ( new [ ] { parent } ) ;
210+ . Append ( new [ ] { configuration , parent } )
211+ . Append ( new [ ] { configuration } )
212+ . Append ( new [ ] { parent } ) ;
213213 foreach ( var args in possibleArgs ) {
214214 var ctor = containerType . GetConstructor ( args ) ;
215- if ( ctor != null )
215+ if ( ctor != null )
216216 return ( IServiceContainer ) ctor . Invoke ( args ) ;
217217 }
218218
@@ -270,7 +270,7 @@ public static IServiceContainer Create(ConfigurationSection section, string name
270270 return Create ( section , name , null ) ;
271271 }
272272
273- /// <summary>
273+ /// <summary>
274274 /// Creates <see cref="IServiceContainer"/> by its configuration.
275275 /// </summary>
276276 /// <param name="section">IoC configuration section.</param>
@@ -284,9 +284,9 @@ public static IServiceContainer Create(ConfigurationSection section, string name
284284 if ( name . IsNullOrEmpty ( ) )
285285 name = string . Empty ;
286286
287- ContainerElement configuration = section == null ? null : section . Containers [ name ] ;
287+ ContainerElement configuration = section == null ? null : section . Containers [ name ] ;
288288
289- if ( configuration == null )
289+ if ( configuration == null )
290290 configuration = new ContainerElement ( ) ;
291291
292292 var registrations = new List < ServiceRegistration > ( ) ;
@@ -299,12 +299,12 @@ public static IServiceContainer Create(ConfigurationSection section, string name
299299 foreach ( var serviceRegistrationElement in configuration . Explicit )
300300 registrations . Add ( serviceRegistrationElement . ToNative ( ) ) ;
301301
302- var currentParent = configuration . Parent . IsNullOrEmpty ( )
303- ? parent
302+ var currentParent = configuration . Parent . IsNullOrEmpty ( )
303+ ? parent
304304 : Create ( section , configuration . Parent , parent ) ;
305-
306- var containerType = configuration . Type . IsNullOrEmpty ( ) ?
307- typeof ( ServiceContainer ) :
305+
306+ var containerType = configuration . Type . IsNullOrEmpty ( ) ?
307+ typeof ( ServiceContainer ) :
308308 Type . GetType ( configuration . Type ) ;
309309 return Create ( containerType , registrations , currentParent ) ;
310310 }
@@ -337,7 +337,7 @@ public ServiceContainer(IEnumerable<ServiceRegistration> configuration)
337337 public ServiceContainer ( IEnumerable < ServiceRegistration > configuration , IServiceContainer parent )
338338 : base ( parent )
339339 {
340- if ( configuration == null )
340+ if ( configuration == null )
341341 return ;
342342 foreach ( var serviceRegistration in configuration )
343343 Register ( serviceRegistration ) ;
@@ -351,7 +351,7 @@ public override void Dispose()
351351 foreach ( var pair in instances ) {
352352 var service = pair . Value ;
353353 var disposable = service as IDisposable ;
354- if ( disposable != null )
354+ if ( disposable != null )
355355 toDispose . Add ( disposable ) ;
356356 }
357357 }
0 commit comments