Skip to content

Instantly share code, notes, and snippets.

@mizrael
Last active September 2, 2019 20:10
Show Gist options
  • Save mizrael/bec897d4f397ddc7b750 to your computer and use it in GitHub Desktop.
Save mizrael/bec897d4f397ddc7b750 to your computer and use it in GitHub Desktop.
simple mongodb database context implementation
public class DbContext : IDbContext
{
public DbContext(IRepositoryFactory repoFactory, string connectionString, string dbName)
{
if (string.IsNullOrWhiteSpace(connectionString))
throw new ArgumentNullException("connectionString");
if (string.IsNullOrWhiteSpace(dbName))
throw new ArgumentNullException("dbName");
this.Posts = repoFactory.Create<Entities.Video>(new RepositoryOptions(connectionString, dbName, "posts"));
this.Users = repoFactory.Create<Entities.User>(new RepositoryOptions(connectionString, dbName,"users") );
this.Tags = repoFactory.Create<Entities.Tag>(new RepositoryOptions(connectionString, dbName, "tags"));
this.Taxonomies = repoFactory.Create<Entities.Taxonomy>(new RepositoryOptions(connectionString, dbName, "taxonomies"));
}
public IRepository<Entities.Post> Posts { get; private set; }
public IRepository<Entities.User> Users { get; private set; }
public IRepository<Entities.Tag> Tags { get; private set; }
public IRepository<Entities.Taxonomy> Taxonomies { get; private set; }
}
@ajmeier29
Copy link

On line one, it should be public class DbContext : IDbContext

@mizrael
Copy link
Author

mizrael commented Sep 2, 2019

nice catch, thanks!

On line one, it should be public class DbContext : IDbContext

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