Ejemplo n.º 1
0
        public IConfigurableNSubContainer Register <TKey, TImpl>(NSubLifetime lifetime) where TImpl : TKey
        {
            var constructors = typeof(TImpl).GetConstructors();

            if (constructors.Length != 1)
            {
                throw new ArgumentException(
                          $"Type '{typeof(TImpl).FullName}' should contain only single public constructor. " +
                          $"Please register type using factory method to avoid ambiguity.");
            }

            var ctor = constructors[0];

            object Factory(ScopeCache scopeCache)
            {
                var args = ctor.GetParameters()
                           .Select(p => ResolveImpl(p.ParameterType, scopeCache))
                           .ToArray();

                return(ctor.Invoke(args));
            }

            AddRegistration(typeof(TKey), new Registration(Factory, lifetime));

            return(this);
        }
Ejemplo n.º 2
0
        public IConfigurableNSubContainer Register <TKey>(Func <INSubResolver, TKey> factory, NSubLifetime lifetime)
        {
            object Factory(ScopeCache scopeCache)
            {
                return(factory.Invoke(new ScopeCacheBoundResolver(this, scopeCache)));
            }

            AddRegistration(typeof(TKey), new Registration(Factory, lifetime));

            return(this);
        }
Ejemplo n.º 3
0
 public Registration(Func <ScopeCache, object> factory, NSubLifetime lifetime)
 {
     _factory  = factory;
     _lifetime = lifetime;
 }