public void Configure(ConfigurationComponents components)
        {
            foreach (var component in components.GetComponents())
            {
                var name = null as string;
                if (component.Type != null)
                {
                    name = _components[component.Type.Name];
                    if (component.Name != null)
                    {
                        _components[component.Type.Name] = component.Name;
                        _infos.Add(component.Name, _infos[name]);
                        _infos.Remove(name);
                        name = component.Name;
                    }
                }
                else if (!string.IsNullOrWhiteSpace(component.Name))
                {
                    name = component.Name;
                }
                else
                {
                    throw new ArgumentException("Use Map<T> or specify `componentName` parameter");
                }

                var filename = null as string;
                if (component.BaseName != null)
                {
                    filename = component.BaseName;
                }
                else if (component.Script != null)
                {
                    filename = Path.GetFileNameWithoutExtension(component.Script);
                }
                else if (component.Style != null)
                {
                    filename = Path.GetFileNameWithoutExtension(component.Style);
                }
                if (filename != null)
                {
                    if (!_infos.ContainsKey(name))
                    {
                        _infos.Add(name, new ComponentInfo {
                        });
                    }
                    _infos[name].ScriptName = filename + _scriptExtension;
                    _infos[name].StyleName  = filename + _styleExtension;
                }

                if (component.Script != null)
                {
                    _assets[_infos[name].ScriptName] = component.Script;
                }
                if (component.Style != null)
                {
                    _assets[_infos[name].StyleName] = component.Style;
                }
            }
        }
Exemplo n.º 2
0
 public static IApplicationBuilder MapComponents(this IApplicationBuilder builder, Action <ConfigurationComponents> configureComponents)
 {
     if (configureComponents != null)
     {
         var componentsService = builder.ApplicationServices.GetRequiredService <IComponentsService>();
         var components        = new ConfigurationComponents();
         configureComponents(components);
         componentsService.Configure(components);
     }
     return(builder);
 }