Example #1
0
 private DefaultConfiguration(Container container)
 {
     _constructorSelector = new ConstructorSelector();
     _dependencyResolver = new DependencyResolver(this);
     _registrationStorage = new RegistrationStorage();
     _typeActivator = new ExpressionActivator(container, _constructorSelector);
 }
Example #2
0
 /// <summary>
 /// Sets the <see cref="ITypeActivator"/> that will be used to 
 /// instantiate object instances.
 /// </summary>
 /// <param name="activator">The <see cref="ITypeActivator"/> that will instantiate types.</param>
 public static void SetActivator(ITypeActivator activator)
 {
     lock (_lock)
     {
         _activator = activator;
     }
 }
Example #3
0
 public DefaultControllerFactory(IServiceProvider serviceProvider, 
                                 ITypeActivator typeActivator,
                                 IControllerActivator controllerActivator)
 {
     _serviceProvider = serviceProvider;
     _typeActivator = typeActivator;
     _controllerActivator = controllerActivator;
 }
 public ModuleActionDescriptorProvider(
     IControllerAssemblyProvider assemblyProvider,
     IServiceProvider services,
     ITypeActivator typeActivator)
 {
     _assemblyProvider = assemblyProvider;
     _services = services;
     _typeActivator = typeActivator;
 }
Example #5
0
 public VirtualPathRazorPageFactory(IRazorCompilationService compilationService,
                                    ITypeActivator typeActivator,
                                    IServiceProvider serviceProvider,
                                    IFileInfoCache fileInfoCache)
 {
     _compilationService = compilationService;
     _activator = typeActivator;
     _serviceProvider = serviceProvider;
     _fileInfoCache = fileInfoCache;
 }
Example #6
0
 public GenericModelBinder(IServiceProvider serviceProvider, ITypeActivator activator)
 {
     _serviceProvider = serviceProvider;
     _activator = activator;
 }
 public Program(ILibraryManager libraryManager, IServiceProvider serviceProvider)
 {
     _libraryManager = libraryManager;
     _serviceProvider = serviceProvider;
     _typeActivator = new TypeActivator();
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorPageActivator"/> class.
 /// </summary>
 public RazorPageActivator(ITypeActivator typeActivator)
 {
     _typeActivator = typeActivator;
     _activationInfo = new ConcurrentDictionary<Type, PageActivationInfo>();
 }
Example #9
0
 IConfigurable IConfigurable.SetTypeActivator(ITypeActivator typeActivator)
 {
     _typeActivator = typeActivator;
     return this;
 }
        public virtual ParameterSetResult Build(ITypeActivator typeActivator,
                                                ITypeConverter typeConverter,
                                                CultureInfo cultureInfo,
                                                NodeSequence sequence,
                                                ParameterSet paramSet)
        {
            BuildContext ctx = new BuildContext(sequence,
                                                paramSet,
                                                typeActivator.CreateInstance(paramSet.UnderlyingType));

            var requiredParameters = new HashSet<Parameter>(paramSet.Where(p => p.GetAttribute<RequiredAttribute>() != null));

            SetDefaultValues(typeConverter, cultureInfo, ctx);

            bool first = true;

            using (IEnumerator<AstNode> enumerator = sequence.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (first && !string.IsNullOrEmpty(ctx.ParameterSet.Command))
                    {
                        LiteralValue literal = enumerator.Current as LiteralValue;
                        if (literal == null || !StringComparer.InvariantCultureIgnoreCase.Equals(literal.Value, ctx.ParameterSet.Command))
                        {
                            // report error: missing/incorrect command
                            ctx.Errors.Add(new BindError(ErrorType.MissingCommand,
                                                         Enumerable.Empty<Parameter>(),
                                                         new AstNode[] { literal },
                                                         string.Format(ErrorMessages.MissingCommand, ctx.ParameterSet.Command)));
                        }
                        if (!enumerator.MoveNext())
                            break;
                    }
                    first = false;

                    if (enumerator.Current.Type == NodeType.Parameter || enumerator.Current.Type == NodeType.Switch)
                    {
                        ParameterName parameterName = (ParameterName)enumerator.Current;
                        Parameter[] parameters;
                        if (ctx.ParameterSet.TryGetParameter(parameterName.Name, out parameters) && parameters.Length == 1)
                        {
                            // remove from "remaining parameters" collection
                            if (!ctx.RemainingParameters.Remove(parameters[0]))
                            {
                                // report error, multiple bindings
                                string message = string.Format(ErrorMessages.MultipleBindings,
                                                               parameterName.Name);

                                ctx.Errors.Add(new BindError(ErrorType.MultipleBindings,
                                                             parameters,
                                                             new AstNode[] { parameterName },
                                                             message));

                                // if the parameter was not of type Switch, skip next node
                                if (parameters[0].Property.PropertyType != typeof(Switch))
                                    enumerator.MoveNext();

                                // handled, continue and skip
                                continue;
                            }

                            // if it's a Switch we can simply set it to "Present"
                            if (parameters[0].Property.PropertyType == typeof(Switch))
                            {
                                if (enumerator.Current.Type == NodeType.Switch)
                                {
                                    SwitchParameter switchParameter = (SwitchParameter)enumerator.Current;
                                    SetPropertyValue(ctx, parameters[0], switchParameter.Value);
                                }
                                else
                                    parameters[0].Property.SetValue(ctx.Instance, Switch.Present, null);

                                requiredParameters.Remove(parameters[0]);
                                // handled, continue and skip
                                continue;
                            }

                            // advance to value 
                            if (!enumerator.MoveNext())
                            {
                                string message = string.Format(ErrorMessages.MissingValue, parameters[0].Name);

                                ctx.Errors.Add(new BindError(ErrorType.MissingValue,
                                                             new[] { parameters[0] },
                                                             new[] { parameterName },
                                                             message));
                                break;
                            }

                            SetPropertyValue(ctx, parameters[0], enumerator.Current);
                            requiredParameters.Remove(parameters[0]);
                        }
                        else if (parameters != null && parameters.Length > 1)
                        {
                            // report error, ambigious name
                            string message = string.Format(ErrorMessages.AmbigiousName,
                                                           parameterName.Name,
                                                           string.Join(", ", parameters.Select(p => p.Name)));

                            ctx.Errors.Add(new BindError(ErrorType.AmbigiousName,
                                                         parameters,
                                                         new AstNode[] { parameterName },
                                                         message));
                        }
                        else
                        {
                            // report error, parameter not found
                            string message = string.Format(ErrorMessages.ArgumentNameMismatch, parameterName.Name);

                            ctx.Errors.Add(new BindError(ErrorType.ArgumentNameMismatch,
                                                         Enumerable.Empty<Parameter>(),
                                                         new AstNode[] { parameterName },
                                                         message));
                        }
                    }
                    else
                    {
                        // positional param
                        var positionalParam = ctx.RemainingParameters.FirstOrDefault(p => p.Position.HasValue);

                        if (positionalParam == null)
                        {
                            // report error, there are no positional parameters
                            string message = string.Format(ErrorMessages.ArgumentPositionMismatch,
                                                           ctx.Sequence.GetInputString(enumerator.Current.SourceInfo));

                            ctx.Errors.Add(new BindError(ErrorType.ArgumentPositionMismatch,
                                                         Enumerable.Empty<Parameter>(),
                                                         new[] { enumerator.Current },
                                                         message));
                        }
                        else
                        {
                            SetPropertyValue(ctx, positionalParam, enumerator.Current);
                            requiredParameters.Remove(positionalParam);
                        }
                    }
                }
            }

            foreach (Parameter missingParameter in requiredParameters)
            {
                string message = string.Format(ErrorMessages.MissingRequiredParameter, missingParameter.Name);

                ctx.Errors.Add(new BindError(ErrorType.MissingRequiredParameter,
                                             new[] { missingParameter },
                                             null,
                                             message));
            }

            return new ParameterSetResult(sequence, ctx.ParameterSet, ctx.Instance, ctx.Errors);
        }
Example #11
0
 public ModuleFactory(IServiceProvider services, ITypeActivator activator)
 {
     _services = services;
     _activator = activator;
 }
		public ServiceAgentAggregator(IApplicationSettings settings, ITypeActivator activator)
		{
			_settings = settings;
			_activator = activator;
		}