eBiz Soa Generic Components - Part 3 - Post Content

eBiz Soa endpoints Input Definitions do not support complex objects!

Well they do now :D

It’s super basic, we use eBiz Soa endpoint JSON as normal, but, we only define one input: PostContent as type string.

PAUSE… Have you figure out where I’m going?

We just set this PostContent string input to the stringify version of our input object and just deserialize it within our component. Yep, that’s it. That’s the magic.

I can’t take full credit for this idea. David Schrubbe (if I’ve miss remember everything, sorry :P, lol) was the first one I know who did this. He came up with the idea while we were both at PerByte. I’ve just expanded the concept to a abstract class.

Post Content Component

using Newtonsoft.Json;
using PB.Rexies.AptifyBits;
using System;

namespace SimplifyAptify.AptifyConfigs.Soa.EndpointComponents
{
    public abstract class PostContentEndpointComponent<TPostData> : BaseEndpointComponent where TPostData : class, new()
    {
        public string PostContent
        {
            get => Properties.GetString(nameof(PostContent));
            set => Properties[nameof(PostContent)] = value;
        }

        protected TPostData PostData { get; private set; }

        public void EnsureSetPostData()
        {
            if (string.IsNullOrWhiteSpace(PostContent))
            {
                throw new ArgumentException("Post content is required.");
            }

            PostData = JsonConvert.DeserializeObject<TPostData>(PostContent);
        }
    }
}

We have a generic abstract class that inherits from our BaseEndpointComponent. The generic is so you can specify the content object your expecting. We then use the EnsureSetPostData to verify we have the stringified value and deserialize it to the PostData property. And that’s it, nice and simple.

Examples and Part 4

Lets now combine everything we’ve talked about and revive Service Data Objects. Yep you read that right, eBiz Soa first Service Data Objects.

Aptify Clients

Continue the conversation on the Community Forums.