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; }