-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from TurnerSoftware/entity-command-writing
EntityWriter system overhaul to support commands
- Loading branch information
Showing
35 changed files
with
855 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/MongoFramework/Infrastructure/Commands/EntityDefinitionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using MongoDB.Driver; | ||
using MongoFramework.Infrastructure.Mapping; | ||
|
||
namespace MongoFramework.Infrastructure.Commands | ||
{ | ||
public static class EntityDefinitionExtensions | ||
{ | ||
public static FilterDefinition<TEntity> CreateIdFilterFromEntity<TEntity>(this IEntityDefinition definition, TEntity entity) | ||
{ | ||
return Builders<TEntity>.Filter.Eq(definition.GetIdName(), definition.GetIdValue(entity)); | ||
} | ||
public static FilterDefinition<TEntity> CreateIdFilter<TEntity>(this IEntityDefinition definition, object entityId) | ||
{ | ||
return Builders<TEntity>.Filter.Eq(definition.GetIdName(), entityId); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/MongoFramework/Infrastructure/Commands/RemoveEntityByIdCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using MongoDB.Driver; | ||
using MongoFramework.Infrastructure.DefinitionHelpers; | ||
using MongoFramework.Infrastructure.Mapping; | ||
|
||
namespace MongoFramework.Infrastructure.Commands | ||
{ | ||
public class RemoveEntityByIdCommand<TEntity> : IWriteCommand<TEntity> where TEntity : class | ||
{ | ||
private object EntityId { get; } | ||
|
||
public RemoveEntityByIdCommand(object entityId) | ||
{ | ||
EntityId = entityId; | ||
} | ||
|
||
public IEnumerable<WriteModel<TEntity>> GetModel() | ||
{ | ||
var definition = EntityMapping.GetOrCreateDefinition(typeof(TEntity)); | ||
yield return new DeleteOneModel<TEntity>(definition.CreateIdFilter<TEntity>(EntityId)); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/MongoFramework/Infrastructure/Commands/RemoveEntityCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using MongoDB.Driver; | ||
using MongoFramework.Infrastructure.DefinitionHelpers; | ||
using MongoFramework.Infrastructure.Mapping; | ||
|
||
namespace MongoFramework.Infrastructure.Commands | ||
{ | ||
public class RemoveEntityCommand<TEntity> : IWriteCommand<TEntity> where TEntity : class | ||
{ | ||
private EntityEntry<TEntity> EntityEntry { get; } | ||
|
||
public RemoveEntityCommand(EntityEntry<TEntity> entityEntry) | ||
{ | ||
EntityEntry = entityEntry; | ||
} | ||
|
||
public IEnumerable<WriteModel<TEntity>> GetModel() | ||
{ | ||
var definition = EntityMapping.GetOrCreateDefinition(typeof(TEntity)); | ||
yield return new DeleteOneModel<TEntity>(definition.CreateIdFilterFromEntity(EntityEntry.Entity)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.