LogoLogo
  • Dosaic
  • Hosting
    • WebHost
    • Generator
    • Abstractions
  • Plugins
    • Authorization
      • Abstractions
      • Keycloak
    • Endpoints
      • Abstractions
      • RestResourceEntity
    • Handlers
      • Abstractions
      • CQRS
    • Jobs
      • Hangfire
    • Management
      • Unleash
    • Mapping
      • Mapster
    • Messaging
      • Abstractions
      • MassTransit
    • Persistence
      • Abstractions
      • EntityFramework
      • InMemory
      • MongoDb
      • S3
      • VaultSharp
    • Validations
      • Abstractions
      • Attribute
  • Extensions
    • RestEase
    • Sqids
  • Testing
    • NUnit
Powered by GitBook
On this page
  • Installation
  • Appsettings.yml
  • Configuration in your plugin host
  • Usage
  • IMongoDbInstance
  1. Plugins
  2. Persistence

MongoDb

Dosaic.Plugins.Persistence.MongoDb is a plugin that allows other Dosaic components to use the MongoDb core to interact with certain databases.

Installation

To install the nuget package follow these steps:

dotnet add package Dosaic.Plugins.Persistence.MongoDb

or add as package reference to your .csproj

<PackageReference Include="Dosaic.Plugins.Persistence.MongoDb" Version="" />

Appsettings.yml

Configure your appsettings.yml with these properties

Postgres for example

mongodb:
  host: "localhost"
  database: "mongodb"
  port: "27017"
  password: "mongodb"
  user: "mongodb"

MongoDbConfiguration.cs

[Configuration("mongodb")]
public class MongoDbConfiguration
{
    public string Host { get; set; } = null!;
    public int Port { get; set; }
    public string Database { get; set; } = null!;
    public string AuthDatabase { get; set; } = null!;
    public string User { get; set; } = null!;
    public string Password { get; set; } = null!;
}

Configuration in your plugin host

Nothing to configure

Usage

IMongoDbInstance

public class ExampleService
{
    private readonly IMongoDbInstance _mongoDbInstance;

    public ExampleService(IMongoDbInstance mongoDbInstance)
    {
        _mongoDbInstance = mongoDbInstance;
    }
    public async Task DoStuff()
    {
        // for example
        var mongoCollection = _mongoDbInstance.GetCollectionFor<MyCollectionEntity>();
    }
}
PreviousInMemoryNextS3

Last updated 19 days ago