Using MongoDB in a C# WinForm app with a repository
-
I decided to port one of my vb apps over to c#, so far so good. I decided to give MongoDB a try and load the MongoDB.Bson, MongoDB.Driver, MongoDB.Driver.Core and MongoDB.Respository.Crud packages from Nuget. I went the repository route like I did in my Angular6 wrapped in .Net Core 2.2 App, but didn't think it through all the way, or it's sort of a test run with it. It just occurred to me that on my repository DBContext configuration, that it uses the appSettings.json file and Microsoft.Extensions.Options to read the MongoDB values. I did some research and found that extension is tied to .Net Core 2. Well I guess I just answered my own question of how to find a workaround for it. This should work, just need to figure out where to initialize it, like in main form loading. I was going to try that C# Mongo Driver but it hasn't been updated since 2010. Is anybody else using MongoDB 4.0 in VS2017 c# Win Form, And have any experience with it? I would to take .Net Core 3 for a test run on this project. It just makes sense to me since I have written lots of .Net Core 2 code already that I can reuse. In my Angular .Net Core 2 App
public class CRMRepository : ICRMRepository
{
private readonly MongoDBContext _context = null;
public CRMRepository(IOptions settings)
{
_context = new MongoDBContext(settings);
}Proposed Thought
public class MongoDB {
public string Connection { get;set; }
public string Database { get; set; }
}public class CRMRepository : ICRMRepository
{
private readonly MongoDBContext _context = null;
public CRMRepository(MongoDB _mongoDB)
{
_context = new MongoDBContext(_mongoDB);
}If it ain't broke don't fix it Discover my world at jkirkerx.com