From e4aea2768a1c2cb559878d0115c7fa4d2bfd9833 Mon Sep 17 00:00:00 2001 From: jay-zahiri <11631617+jay-zahiri@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:39:58 +0100 Subject: [PATCH 1/3] Restored MartenOps.Store and added MartenOps.StoreMany --- src/Persistence/Wolverine.Marten/IMartenOp.cs | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Persistence/Wolverine.Marten/IMartenOp.cs b/src/Persistence/Wolverine.Marten/IMartenOp.cs index b5069841..c88eaa5f 100644 --- a/src/Persistence/Wolverine.Marten/IMartenOp.cs +++ b/src/Persistence/Wolverine.Marten/IMartenOp.cs @@ -24,18 +24,35 @@ public static class MartenOps /// /// Return a side effect of storing the specified document in Marten /// + /// + /// + /// + /// + public static StoreDoc Store(T document) where T : notnull + { + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + + return new StoreDoc(document); + } + + /// + /// Return a side effect of storing many documents of a specific document type in Marten + /// /// /// /// /// - public static StoreDoc Store(params T[] documents) where T : notnull + public static StoreManyDocs StoreMany(params T[] documents) where T : notnull { if (documents == null) { throw new ArgumentNullException(nameof(documents)); } - return new StoreDoc(documents); + return new StoreManyDocs(documents); } /// @@ -225,10 +242,25 @@ public void Execute(IDocumentSession session) } public class StoreDoc : DocumentOp where T : notnull +{ + private readonly T _document; + + public StoreDoc(T document) : base(document) + { + _document = document; + } + + public override void Execute(IDocumentSession session) + { + session.Store(_document); + } +} + +public class StoreManyDocs : DocumentsOp where T : notnull { private readonly T[] _documents; - public StoreDoc(params T[] documents) : base(documents) + public StoreManyDocs(T[] documents) : base(documents) { _documents = documents; } @@ -285,10 +317,22 @@ public override void Execute(IDocumentSession session) } public abstract class DocumentOp : IMartenOp +{ + public object Document { get; } + + protected DocumentOp(object document) + { + Document = document; + } + + public abstract void Execute(IDocumentSession session); +} + +public abstract class DocumentsOp : IMartenOp { public object[] Documents { get; } - protected DocumentOp(params object[] documents) + protected DocumentsOp(params object[] documents) { Documents = documents; } From 53d27b444d6e63695696bbdc7aca4aecf4f23f09 Mon Sep 17 00:00:00 2001 From: jay-zahiri <11631617+jay-zahiri@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:23:49 +0100 Subject: [PATCH 2/3] Perform casting to IEnumerable --- src/Persistence/Wolverine.Marten/IMartenOp.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Persistence/Wolverine.Marten/IMartenOp.cs b/src/Persistence/Wolverine.Marten/IMartenOp.cs index c88eaa5f..8f73b5b1 100644 --- a/src/Persistence/Wolverine.Marten/IMartenOp.cs +++ b/src/Persistence/Wolverine.Marten/IMartenOp.cs @@ -260,9 +260,9 @@ public class StoreManyDocs : DocumentsOp where T : notnull { private readonly T[] _documents; - public StoreManyDocs(T[] documents) : base(documents) + public StoreManyDocs(IEnumerable documents) : base(documents.Cast()) { - _documents = documents; + _documents = documents.ToArray(); } public override void Execute(IDocumentSession session) @@ -332,9 +332,9 @@ public abstract class DocumentsOp : IMartenOp { public object[] Documents { get; } - protected DocumentsOp(params object[] documents) + protected DocumentsOp(IEnumerable documents) { - Documents = documents; + Documents = documents.ToArray(); } public abstract void Execute(IDocumentSession session); From 4a4e3684354429ef81a1aac29fbf9e73cda842b7 Mon Sep 17 00:00:00 2001 From: jay-zahiri <11631617+jay-zahiri@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:40:57 +0100 Subject: [PATCH 3/3] DX alignment --- src/Persistence/Wolverine.Marten/IMartenOp.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Persistence/Wolverine.Marten/IMartenOp.cs b/src/Persistence/Wolverine.Marten/IMartenOp.cs index 8f73b5b1..b13518ea 100644 --- a/src/Persistence/Wolverine.Marten/IMartenOp.cs +++ b/src/Persistence/Wolverine.Marten/IMartenOp.cs @@ -260,11 +260,13 @@ public class StoreManyDocs : DocumentsOp where T : notnull { private readonly T[] _documents; - public StoreManyDocs(IEnumerable documents) : base(documents.Cast()) + public StoreManyDocs(params T[] documents) : base(documents.Cast().ToArray()) { - _documents = documents.ToArray(); + _documents = documents; } + public StoreManyDocs(IList documents) : this(documents.ToArray()) { } + public override void Execute(IDocumentSession session) { session.Store(_documents); @@ -332,10 +334,10 @@ public abstract class DocumentsOp : IMartenOp { public object[] Documents { get; } - protected DocumentsOp(IEnumerable documents) + protected DocumentsOp(params object[] documents) { - Documents = documents.ToArray(); + Documents = documents; } public abstract void Execute(IDocumentSession session); -} \ No newline at end of file +}