Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using MongoDB in a C# WinForm app with a repository

Using MongoDB in a C# WinForm app with a repository

Scheduled Pinned Locked Moved C#
mongodbcsharpquestionjavascriptasp-net
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups