Exemplo n.º 1
0
        public override object Activate(DefaultTypeResolver container)
        {
            var parameters = new object?[_parameters.Count];

            for (var i = 0; i < _parameters.Count; i++)
            {
                var parameter = _parameters[i];
                if (parameter.ParameterType == typeof(DefaultTypeResolver))
                {
                    parameters[i] = container;
                }
                else
                {
                    var resolved = container.Resolve(parameter.ParameterType);
                    if (resolved == null)
                    {
                        if (!parameter.IsOptional)
                        {
                            throw new InvalidOperationException($"Could not find registration for '{parameter.ParameterType.FullName}'.");
                        }

                        parameters[i] = null;
                    }
                    else
                    {
                        parameters[i] = resolved;
                    }
                }
            }

            return(_constructor.Invoke(parameters));
        }
        public ITypeResolver Build()
        {
            var container = new DefaultTypeResolver();

            while (_registry.Count > 0)
            {
                var action = _registry.Dequeue();
                action(container.Registry);
            }

            return(container);
        }
Exemplo n.º 3
0
 public abstract object Activate(DefaultTypeResolver container);
Exemplo n.º 4
0
 public override object Activate(DefaultTypeResolver container)
 {
     return(_instance);
 }
Exemplo n.º 5
0
 public override object Activate(DefaultTypeResolver container)
 {
     return(_result ??= _activator.Activate(container));
 }