/// <summary> /// Optionally creates a snapshot of the aggregate root /// </summary> /// <param name="aggregateRoot">Aggregate root instance to snapshot</param> protected bool TryCreateSnapshot(AggregateRoot aggregateRoot) { if (!(aggregateRoot is IAggregateRootWithSnapshot)) { return(false); } var dynamicRoot = aggregateRoot.AsDynamic(); // Only create a snapshot of the root requires it if (!dynamicRoot.ShouldCreateSnapshot()) { return(false); } var snapshot = ((IAggregateRootWithSnapshot)aggregateRoot).CreateGenericSnapshot(); if (snapshot == null) { return(false); } // Dynamically invoke the SaveSnapshot<T> method of the snapshot store _snapshotStore.InvokeGenericMethod("SaveSnapshot", ((IAggregateRootWithSnapshot)aggregateRoot).GetGenericType(), snapshot); return(true); }