/// <summary> /// /// </summary> /// <param name="body"></param> /// <returns></returns> public DomainEvent Deserialize(string body) { var eventData = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, object> > >(body); var data = eventData["data"]; var attributesString = data["attributes"].ToString(); var attributes = JsonConvert.DeserializeObject <Dictionary <string, string> >(attributesString !); var domainEventType = DomainEventsInformation.ForName((string)data["type"]); var instance = ReflectionHelper.CreateInstance <DomainEvent>(domainEventType); var domainEvent = (DomainEvent)domainEventType .GetTypeInfo() .GetDeclaredMethod(nameof(DomainEvent.FromPrimitives)) ?.Invoke(instance, new object[] { attributes["id"], attributes, data["id"].ToString(), data["occurred_on"].ToString() }); return(domainEvent); }
/// <summary> /// /// </summary> /// <param name="services"></param> /// <param name="domainAssembly"></param> /// <returns></returns> public static IServiceCollection AddDomainEvents(this IServiceCollection services, Assembly domainAssembly) { DomainEventsInformation.Register(domainAssembly); return(services); }