Is the EPiServer.Shell.UIDescriptorRegistry.InitializeDescriptors method really working as inteded? (v7.14)

Vote:
 

I am trying to use a UIDescriptorProvider to register icon classes for my pages, this works... sometimes. If i disassemble the UIDescriptorRegistry class, the init method look like this:

 private List InitializeDescriptors()
    {
      foreach (IUIDescriptorInitializer descriptorInitializer in this._initializers)
        descriptorInitializer.Initialize(this);
      Dictionary dictionary = Enumerable.ToDictionary((IEnumerable) this._uiDescriptors, (Func) (descriptor => descriptor.TypeIdentifier), (IEqualityComparer) StringComparer.OrdinalIgnoreCase);
      foreach (UIDescriptorProvider descriptorProvider in this._descriptorProviders)
      {
        foreach (UIDescriptor uiDescriptor in descriptorProvider.GetDescriptors())
        {
          string typeIdentifier = uiDescriptor.TypeIdentifier;
          if (dictionary.ContainsKey(typeIdentifier))
            UIDescriptorRegistry._log.DebugFormat("Discarding ui descriptor registration for type {0} provided by {1} since a desciptor for the type is already registered.", (object) typeIdentifier, (object) descriptorProvider.GetType().FullName);
          else
            dictionary.Add(typeIdentifier, uiDescriptor);
        }
      }
      foreach (UIDescriptor descriptor in dictionary.Values)
        UIDescriptorRegistry.SetBaseTypeIdentifier(descriptor, (IEnumerable) dictionary.Values);
      return Enumerable.ToList((IEnumerable) dictionary.Values);
    }

Assuming the code above, whatever UIDescriptorProvider happen to come first, will register the uidescriptor and all that follows will be ignored as per the if-clause in the middle of the method.

Now, am I missing something here? Like a sortorder that determine in what order these should be registered. But even so, is this intended to be a battle? I suppose I could roll my own UIDescriptorRegistry, but I rather get some clarification if current behaviour is intended.

I have "solved" it temporary for now by using the obsolete IUIDescriptorInitializer interface & serviceconfig as those are initialized before any UIDescriptorProvider in the InitializeDescriptors method.

I would ideally like a "Update" method in the UIDescriptorRegistry, where I could just append a classname since that is all I want.

#112167
Oct 23, 2014 16:07
Vote:
 

Yes it is, the order of the initializers and the providers are unknown so you can't rely on other descriptors being there at that point. 

In your case, the idea is to change the existing descriptors using an initializer module. When you get the descriptors in the example below, all initialization and registration should be completed.

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Cms.Shell.InitializableModule))]
public class InitializationModule : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        var registry = context.Locate.Advanced.GetInstance<UIDescriptorRegistry>();
        foreach (var descriptor in registry.UIDescriptors)
        {
            descriptor.DefaultView = "formedit";
        }
    }
} 

Hope this solves your problem.
 

#112168
Oct 23, 2014 17:00
Vote:
 

Thanks for the clarification, that makes sense. I tried it now and it seem to work.

If my icons start to act up again I'll come back to haunt you!

#112199
Oct 24, 2014 12:08
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.