Let us say we have an abstract class ExternalDomainEvent and three derived classes ExternalDomainEventA, ExternalDomainEventB, ExternalDomainEventC. I also have a method that returns ExternalDomainEvent where ExternalDomainEvent is either instance of ExternalDomainEventA or ExternalDomainEventB or ExternalDomainEventC.
When I add an instance of ExternalDomainEvent to a stream I seem to lose the information of whether ExternalDomainEvent is an instance of ExternalDomainEventA or ExternalDomainEventB or ExternalDomainEventC.
Is it necessary to add the actual type as meta data or can I obtain the original type during catchup?
Thanks.
Christian
Maybe you can put your code? We don't do anything at all with types so
this is definitely in your code
Thanks. I am currently using this:
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using JustGiving.EventStore.Http.Client.Common.Utils;
using JustGiving.EventStore.Http.Client.Exceptions;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace JustGiving.EventStore.Http.Client
{
/// <summary>
/// EventStore Http connection.
/// <para>
/// As this connection is backed by <see cref="HttpClient"/>, clients are subject to connection management per <see cref="ServicePointManager"/>.
/// See https://msdn.microsoft.com/en-us/library/system.net.servicepoint%28v=vs.110%29.aspx for details on configuration options.
This file has been truncated. show original
more precisely :
public async Task AppendToStreamAsync(string stream, int expectedVersion, params NewEventData events)
{
var url = _endpoint + “/streams/” + stream;
Log.Info(_log, “Appending {0} events to {1}”, events==null?0 :events.Length, stream);
using (var client = GetClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Content = new StringContent(JsonConvert.SerializeObject(events), Encoding.UTF8, “application/vnd.eventstore.events+json”);
request.Headers.Add(“ES-ExpectedVersion”, expectedVersion.ToString());
var result = await _httpClientProxy.SendAsync(client, request);
if (!result.IsSuccessStatusCode)
{
Log.Error(_log, “Error appending {0} events to {1}”, events == null ? 0 : events.Length, url);
throw new EventStoreHttpException(result.Content.ToString(), result.ReasonPhrase, result.StatusCode);
}
}
}
Where do you set the event type? Its being passed in
Could you please be so kind and point me in the right direction on how to set this via this http approach?
This isn't our code. It is either set in the body of the http post or
a head from our perspective the library appears to use the body
mechanism
That said you pass into this function something called neweventdata
https://github.com/JustGiving/JustGiving.EventStore.Http/blob/master/src/JustGiving.EventStore.Http.Client/NewEventData.cs#L18
which has the event type on it.
You are setting this in the code one level up from the code you sent
(you pass an array of NewEventData to the function you are calling)
Cheers,
Greg