Mendz.Data.MongoDB is on GitHub and NuGet

Mendz.Data.MongoDB, which provides a generic Mendz.Data-aware context for MongoDB, is now on GitHub and NuGet!

Mendz.Data.MongoDB provides MongoDbDataContext, which derives from Mendz.Data.Common's GenericDbDataContextBase, an implementation of IDbDataContext. Repositories based on DbRepositoryBase are expected to be passed with an IDbDataContext instance. MongoDbDataContext can be that instance.

MongoDbDataContext assumes that appsettings.json contains an entry/section for DataSettings.

{
    "DataSettings": {
        "ConnectionStrings": {
            "MongoDBClient" : "MongoDB client specification",
            "MongoDBContext" : "MongoDB context specification"
        }
    }
}

In the application startup or initialization routine, the DataSettings should be loaded into DataSettingOptions as follows (the application must reference Mendz.Data):

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            DataSettingOptions.Initialize(
                Configuration.GetSection("DataSettings").Get<DataSettings>());
        }

Mendz.Data-aware repositories using MongoDbDataContext can have a skeleton that looks like the following:

    public class TestRepository : DbRepositoryBase<MongoDbDataContext>
    {
        ...
    }

In an ASP.Net MVC application, for example, the controller code can use TestRepository as follows:

    public class TestController : Controller
    {
        // GET: Test
        public ActionResult Index(int id)
        {
            using (TestRepository testRepository = new TestRepository())
            {
                return View(testRepository.Search(id, null));
            }
        }
    }

If you are ready to create Mendz.Data-aware repositories that connect to MongoDB, and your strategy is to use MongoDB's .Net driver, you can get Mendz.Data.MongoDB from NuGet: https://www.nuget.org/packages/Mendz.Data.MongoDB/. This package has dependency on Mendz.Data, which is included when you download/install Mendz.Data.MongoDB. Note that Mendz.Data.MongoDB references MongoDB's .Net driver.

Comments