src/Topelab.Core.Resolver.Unity/ResolveInfoCollectionFactory.cs
/// <summary>
/// Registers within the specified container the specified resolve info collection.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="resolveInfoCollection">The resolve info collection.</param>
/// <param name="constructorsByKey">The constructors by key.</param>
Registers within the specified container the specified resolve info collection.
Registers within the specified container the specified resolve info collection .
internal static void Register(this IUnityContainer container, ResolveInfoCollection resolveInfoCollection, Dictionary<string, ConstructorInfo> constructorsByKey)
        {
            resolveInfoCollection.ForEach(resolveInfo =>
            {
                var key = ResolverKeyFactory.Create(resolveInfo);
                var injectionMember = resolveInfo.ConstructorParamTypes?.Length > 0 ? Invoke.Constructor(resolveInfo.ConstructorParamTypes) : null;
                var constructorInfo = GetConstructorInfo(resolveInfo);
                if (constructorInfo != null && key != null)
                {
                    constructorsByKey[key] = constructorInfo;
                }
                switch (resolveInfo.ResolveMode)
                {
                    case ResolveModeEnum.Instance:
                        container.RegisterInstance(resolveInfo.TypeFrom, resolveInfo.Instance);
                        break;
                    case ResolveModeEnum.Factory:
                        switch (resolveInfo.ResolveLifeCycle)
                        {
                            case ResolveLifeCycleEnum.Transient:
                                container.RegisterFactory(resolveInfo.TypeFrom, key, c => resolveInfo.Factory.Invoke(c.Resolve<IResolver>()), FactoryLifetime.PerResolve);
                                break;
                            case ResolveLifeCycleEnum.Scoped:
                                container.RegisterFactory(resolveInfo.TypeFrom, key, c => resolveInfo.Factory.Invoke(c.Resolve<IResolver>()), FactoryLifetime.PerContainer);
                                break;
                            case ResolveLifeCycleEnum.Singleton:
                                container.RegisterFactory(resolveInfo.TypeFrom, key, c => resolveInfo.Factory.Invoke(c.Resolve<IResolver>()), FactoryLifetime.Singleton);
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        switch (resolveInfo.ResolveLifeCycle)
                        {
                            case ResolveLifeCycleEnum.Singleton:
                                if (resolveInfo.ConstructorParamTypes.Length > 0)
                                {
                                    container.RegisterSingleton(resolveInfo.TypeFrom, resolveInfo.TypeTo, key, injectionMember);
                                }
                                else
                                {
                                    container.RegisterSingleton(resolveInfo.TypeFrom, resolveInfo.TypeTo, key);
                                }
                                break;
                            case ResolveLifeCycleEnum.Scoped:
                                if (resolveInfo.ConstructorParamTypes.Length > 0)
                                {
                                    container.RegisterType(resolveInfo.TypeFrom, resolveInfo.TypeTo, key, TypeLifetime.PerContainer, injectionMember);
                                }
                                else
                                {
                                    container.RegisterType(resolveInfo.TypeFrom, resolveInfo.TypeTo, key, TypeLifetime.PerContainer);
                                }
                                break;
                            default:
                                if (resolveInfo.ConstructorParamTypes.Length > 0)
                                {
                                    container.RegisterType(resolveInfo.TypeFrom, resolveInfo.TypeTo, key, injectionMember);
                                }
                                else
                                {
                                    container.RegisterType(resolveInfo.TypeFrom, resolveInfo.TypeTo, key);
                                }
                                break;
                        }
                        break;
                }
            });
        }
internal static void Register ( this IUnityContainer container , ResolveInfoCollection resolveInfoCollection , Dictionary < string , ConstructorInfo > constructorsByKey ) { resolveInfoCollection . ForEach ( resolveInfo => { var key = ResolverKeyFactory . Create ( resolveInfo ) ; var injectionMember = resolveInfo . ConstructorParamTypes ? . Length > 0 ? Invoke . Constructor ( resolveInfo . ConstructorParamTypes ) : null ; var constructorInfo = GetConstructorInfo ( resolveInfo ) ; if ( constructorInfo != null && key != null ) { constructorsByKey [ key ] = constructorInfo ; } switch ( resolveInfo . ResolveMode ) { case ResolveModeEnum . Instance : container . RegisterInstance ( resolveInfo . TypeFrom , resolveInfo . Instance ) ; break ; case ResolveModeEnum . Factory : switch ( resolveInfo . ResolveLifeCycle ) { case ResolveLifeCycleEnum . Transient : container . RegisterFactory ( resolveInfo . TypeFrom , key , c => resolveInfo . Factory . Invoke ( c . Resolve < IResolver > ( ) ) , FactoryLifetime . PerResolve ) ; break ; case ResolveLifeCycleEnum . Scoped : container . RegisterFactory ( resolveInfo . TypeFrom , key , c => resolveInfo . Factory . Invoke ( c . Resolve < IResolver > ( ) ) , FactoryLifetime . PerContainer ) ; break ; case ResolveLifeCycleEnum . Singleton : container . RegisterFactory ( resolveInfo . TypeFrom , key , c => resolveInfo . Factory . Invoke ( c . Resolve < IResolver > ( ) ) , FactoryLifetime . Singleton ) ; break ; default : break ; } break ; default : switch ( resolveInfo . ResolveLifeCycle ) { case ResolveLifeCycleEnum . Singleton : if ( resolveInfo . ConstructorParamTypes . Length > 0 ) { container . RegisterSingleton ( resolveInfo . TypeFrom , resolveInfo . TypeTo , key , injectionMember ) ; } else { container . RegisterSingleton ( resolveInfo . TypeFrom , resolveInfo . TypeTo , key ) ; } break ; case ResolveLifeCycleEnum . Scoped : if ( resolveInfo . ConstructorParamTypes . Length > 0 ) { container . RegisterType ( resolveInfo . TypeFrom , resolveInfo . TypeTo , key , TypeLifetime . PerContainer , injectionMember ) ; } else { container . RegisterType ( resolveInfo . TypeFrom , resolveInfo . TypeTo , key , TypeLifetime . PerContainer ) ; } break ; default : if ( resolveInfo . ConstructorParamTypes . Length > 0 ) { container . RegisterType ( resolveInfo . TypeFrom , resolveInfo . TypeTo , key , injectionMember ) ; } else { container . RegisterType ( resolveInfo . TypeFrom , resolveInfo . TypeTo , key ) ; } break ; } break ; } } ) ; }
Registers within the specified container the specified resolve info collection.
Registers within the specified container the specified resolve info collection .
IUnityContainer
this
resolveInfoCollection
ResolveInfoCollection
The resolve info collection.
The resolve info collection .
constructorsByKey
Dictionary<string, ConstructorInfo>
The constructors by key.
The constructors by key .
container
None