Skip to content

Instantly share code, notes, and snippets.

@mizrael
Created December 29, 2015 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizrael/9e0669598fad62cc998b to your computer and use it in GitHub Desktop.
Save mizrael/9e0669598fad62cc998b to your computer and use it in GitHub Desktop.
simple Mongodb repository factory implementation
public class RepositoryFactory : IRepositoryFactory
{
private readonly IMongoDatabaseFactory _dbFactory;
public RepositoryFactory(IMongoDatabaseFactory dbFactory)
{
if (dbFactory == null)
throw new ArgumentNullException("dbFactory");
_dbFactory = dbFactory;
}
public IRepository<TEntity> Create<TEntity>(RepositoryOptions options)
{
if (options == null) throw new ArgumentNullException("options");
var db = _dbFactory.Connect(options.ConnectionString, options.DbName);
return new Repository<TEntity>(db.GetCollection<TEntity>(options.CollectionName));
}
}
@mizrael
Copy link
Author

mizrael commented Sep 2, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment