[DECLINED] Simplify Squidex.ClientLibrary classes

Squidex.ClientLibrary currently has this structure for each schema:

public sealed class BlogPostData
{
    // Squidex delivers hash maps for each field, but the 
    // InvariantConverter helps to simplify the model.
    [JsonConverter(typeof(InvariantConverter))]
    public string Title { get; set; }

    [JsonConverter(typeof(InvariantConverter))]
    public string Slug { get; set; }

    // For localizable fields you can use dictionaries.
    public Dictionary<string, string> Text { get; set; }
}

public sealed class BlogPost : SquidexEntityBase<BlogPostData>
{
}

var client = clientManager.GetClient<BlogPost, BlogPostData>("posts");

I think that instead of using two classes (of which one is empty), we can simplify the classes to the following:

public class FlatSM : SquidexEntityBase<FlatSM>
{
}

I would also suggest to remove the schema name from the GetClient() call and move it into an attribute on the data class. Therefore, we don’t need to type use name of schema every time we instantiate the ClientManager for the schema.

In summary, I’m suggesting something like this:

[Schema(Name="posts")]
public sealed class BlogPost : SquidexEntityBase<BlogPostData>
{
}

What are your thoughts?

The code formatting omitted some of my code. I meant

public sealed class BlogPost : SquidexEntityBase<BlogPost>

You would loose a lot of type safety with this approach. Because how would you know what to pass in for Create or Update calls?

Hi @Sebastian,

okay, forget about the attribute. I just noticed that you still need the name of the content as parameter to specify which content entity you want to update.

What about merging both classes into one? :wink:

The problem is that the post needs the data only and the get the data plus all metadata like id.

1 Like

Thanks for your explanation! Maybe you can add a couple of sentences to the documentation of Squidex.ClientLibrary that outline why there are two classes :slight_smile:

You can close this ticket.

Sure, I don’t like the solution either, but I could not find a better. If you have a concrete idea: A PR is very welcome.

Have you found something? Can i close it?

Unfortunately, no I haven’t found any improvement as of yet. We experimented a lot with referenced items and ran into other problems / inconveniences for which we’ll probably open another feature request in the next couple of days :-/

You can close this ticket for now.

This topic was automatically closed after 2 days. New replies are no longer allowed.