Refactoring Remove method in MongoDb Repository

First method

public void RemoveById(Guid id)
{
  _collection.Remove(Query.EQ("_id", id));
}

Using:

_repository.RemoveById(id);

Disadvantages:

  • Grownup Repository class with RemoveSomething() methods
  • Depends on string constants (“_id”)

Second method

public void RemoveByQuery(IMongoQuery query)
{
  _collection.Remove(query);
}

Using:

_repository.RemoveByQuery(Query.EQ("_id", id));

Disadvantages:

  • Business logic depends on MongoDb Driver Queries (Query.EQ("_id", id))
  • Depends on string constants (“_id”)

Third method

public void Remove<TValue>(Expression<Func<TEntity, TValue>> expression, TValue value)
{
  _collection.Remove(Query<TEntity>.EQ(expression, value));
}

Using:

_repository.Remove(x => x.Id, id);

Disadvantages:

  • Only eqaul condition (Query.EQ)

Advantages:

  • Can use a lambda expression instead of string constants
  • Clear Repository class

Fourth method

public void Remove(Expression<Func<TEntity, bool>> whereExpression)
{
  _collection.Remove(Query<TEntity>.Where(whereExpression));
}

Using:

_repository.Remove(x => x.Id == id);

Advantages:

  • Can use a lambda expression instead of string constants
  • Clear Repository class
  • Can use any lambda expression (x => x.Id == id)

Powershell script for nginx log rotate

Run Psake tasks on TeamCity

File tree:

.
├── build.cmd
└── Scripts
    ├── default.ps1
    └── NuGet.exe

build.cmd

Using:

build.cmd taskName

Refactoring build script on Psake

Simple task for clean project dir:

Using options maxRetries.

More in wiki https://github.com/psake/psake/wiki/How-can-I-set-retry-rules-for-a-task%3F

Simple gruntfile

Complie coffee to js, run jasmine tests after coffee files changed