/// <summary> /// Gets the domain event. /// </summary> /// <param name="domainEvent">The domain event.</param> /// <returns></returns> private async Task <IDomainEvent> GetDomainEvent(Object domainEvent) { String eventType = this.Request.Query["eventType"].ToString(); var type = TypeMap.GetType(eventType); if (type == null) { throw new Exception($"Failed to find a domain event with type {eventType}"); } JsonIgnoreAttributeIgnorerContractResolver jsonIgnoreAttributeIgnorerContractResolver = new JsonIgnoreAttributeIgnorerContractResolver(); var jsonSerialiserSettings = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented, DateTimeZoneHandling = DateTimeZoneHandling.Utc, ContractResolver = jsonIgnoreAttributeIgnorerContractResolver }; if (type.IsSubclassOf(typeof(DomainEvent))) { var json = JsonConvert.SerializeObject(domainEvent, jsonSerialiserSettings); DomainEventFactory domainEventFactory = new(); return(domainEventFactory.CreateDomainEvent(json, type)); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="DomainEventFactory2" /> class. /// </summary> public DomainEventFactory() { JsonIgnoreAttributeIgnorerContractResolver jsonIgnoreAttributeIgnorerContractResolver = new JsonIgnoreAttributeIgnorerContractResolver(); JsonConvert.DefaultSettings = () => { return(new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented, DateTimeZoneHandling = DateTimeZoneHandling.Utc, ContractResolver = jsonIgnoreAttributeIgnorerContractResolver }); }; }