diff --git a/zero.Core/Architecture/Blueprints/Blueprint.cs b/zero.Core/Architecture/Blueprints/Blueprint.cs index ca39001e..49ec7b8c 100644 --- a/zero.Core/Architecture/Blueprints/Blueprint.cs +++ b/zero.Core/Architecture/Blueprints/Blueprint.cs @@ -3,6 +3,22 @@ using System.Text.Json.Serialization; namespace zero.Architecture; +public sealed class DefaultShallowBlueprint : Blueprint +{ + public DefaultShallowBlueprint(Type type) : base() + { + Alias = "shallow.default"; + ContentType = type; + LockAll(); + } + + + protected override BlueprintField AddField(Expression> selector) + { + throw new InvalidOperationException("Shallow blueprints can not contain unlocked fields"); + } +} + /// /// /// @@ -80,7 +96,7 @@ public class Blueprint : Blueprint where T : ZeroEntity, new() /// /// Lock a field so it always get synchronized no and cannot be changed /// - public void LockAll() + public virtual void LockAll() { UnlockedFields = new(); } @@ -89,19 +105,19 @@ public class Blueprint : Blueprint where T : ZeroEntity, new() /// /// Lock a field so it always get synchronized no and cannot be changed /// - public void Lock(Expression> selector) + public virtual void Lock(Expression> selector) { RemoveField(selector); } - public void Unlock(Expression> selector) + public virtual void Unlock(Expression> selector) { AddField(selector); } - public void UnlockDefaults() + public virtual void UnlockDefaults() { AddField(x => x.Name); AddField(x => x.Alias); @@ -124,7 +140,7 @@ public class Blueprint : Blueprint where T : ZeroEntity, new() /// /// Get existing field or create a new one /// - protected BlueprintField AddField(Expression> selector) + protected virtual BlueprintField AddField(Expression> selector) { BlueprintField tempField = new(selector); BlueprintField storedField = UnlockedFields.FirstOrDefault(x => x.FieldName.Equals(tempField.FieldName, StringComparison.InvariantCultureIgnoreCase)); @@ -142,7 +158,7 @@ public class Blueprint : Blueprint where T : ZeroEntity, new() /// /// Removes a field /// - protected void RemoveField(Expression> selector) + protected virtual void RemoveField(Expression> selector) { BlueprintField tempField = new(selector); @@ -163,9 +179,9 @@ public abstract class Blueprint /// Type of the associated entity /// [JsonIgnore] - public Type ContentType { get; private set; } + public Type ContentType { get; protected set; } - public string Alias { get; private set; } + public string Alias { get; protected set; } /// /// String comparer for property name comparison diff --git a/zero.Core/Architecture/Blueprints/BlueprintConfiguration.cs b/zero.Core/Architecture/Blueprints/BlueprintConfiguration.cs index 494e5ca4..5e3472f6 100644 --- a/zero.Core/Architecture/Blueprints/BlueprintConfiguration.cs +++ b/zero.Core/Architecture/Blueprints/BlueprintConfiguration.cs @@ -8,7 +8,7 @@ public class BlueprintConfiguration /// /// Id of the entity the synchronisation is based upon /// - public string Id { get; set; } + public string TargetId { get; set; } /// /// A shallow copy of a blueprint can not be changed and is always fully synchronised with the parent entity diff --git a/zero.Core/Architecture/Blueprints/BlueprintInterceptor.cs b/zero.Core/Architecture/Blueprints/BlueprintInterceptor.cs index 3a81e91c..a61ebb34 100644 --- a/zero.Core/Architecture/Blueprints/BlueprintInterceptor.cs +++ b/zero.Core/Architecture/Blueprints/BlueprintInterceptor.cs @@ -48,7 +48,7 @@ public class BlueprintInterceptor : Interceptor, IBlueprintIntercept { if (!BlueprintService.TryGetBlueprint(model, out Blueprint blueprint)) { - return; + blueprint = new DefaultShallowBlueprint(model.GetType()); } int count = 0; @@ -63,7 +63,10 @@ public class BlueprintInterceptor : Interceptor, IBlueprintIntercept if (child == null) { child = ObjectCopycat.Clone(model); - child.Blueprint = new() { Id = model.Id }; + child.Blueprint = new() + { + TargetId = model.Id + }; } else {