public void Register(ContanerRegistrationContext context) { ICReg reg; var possibleConstructors = _constructorTrait.ReturnPossibleConstructors(_implementationType).ToList(); var bestConstructor = _constructorTrait.ChooseConstructor(_implementationType, possibleConstructors); if (bestConstructor == null) { throw new ArgumentException($"Cannot find public constructor for {_implementationType.FullName}"); } switch (_liveScopeTrait.Lifetime) { case Lifetime.AlwaysNew: reg = new AlwaysNewImpl(_implementationType, bestConstructor); break; case Lifetime.Singleton: reg = new SingletonImpl(_implementationType, new AlwaysNewImpl(_implementationType, bestConstructor), context.SingletonCount); context.SingletonCount++; break; default: throw new ArgumentOutOfRangeException(); } context.AddCReg(_asTrait.GetAsTypesFor(_implementationType), _asTrait.PreserveExistingDefaults, reg); }
public void Register(ContanerRegistrationContext context) { ICRegILGen reg = new FactoryWithContainerParamImpl(context.AddInstance(_factory), _implementationType); if (_liveScopeTrait.Lifetime == Lifetime.Singleton) { reg = new SingletonImpl(_implementationType, reg, context.SingletonCount); context.SingletonCount++; } context.AddCReg(_asTrait.GetAsTypesFor(_implementationType), _asTrait.PreserveExistingDefaults, (ICReg)reg); }