DotnetBoilerplate.Components.Domain.MongoDb 2.0.0

Suggested Alternatives

DotnetBaseKit.Components.Domain.MongoDb

Additional Details

Changed name from DotnetBoilerplate to DotnetBaseKit

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package DotnetBoilerplate.Components.Domain.MongoDb --version 2.0.0
NuGet\Install-Package DotnetBoilerplate.Components.Domain.MongoDb -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotnetBoilerplate.Components.Domain.MongoDb" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotnetBoilerplate.Components.Domain.MongoDb --version 2.0.0
#r "nuget: DotnetBoilerplate.Components.Domain.MongoDb, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotnetBoilerplate.Components.Domain.MongoDb as a Cake Addin
#addin nuget:?package=DotnetBoilerplate.Components.Domain.MongoDb&version=2.0.0

// Install DotnetBoilerplate.Components.Domain.MongoDb as a Cake Tool
#tool nuget:?package=DotnetBoilerplate.Components.Domain.MongoDb&version=2.0.0

DotnetBoilerplate.Components.Domain.MongoDB Documentation

This documentation provides an overview of the purpose, and usage for the DotnetBoilerplate.Components.Domain.MongoDB package.

<details open>

<summary>Table of Contents</summary>

</details>

Overview

The DotnetBoilerplate.Components.Domain.MongoDB package provides essential base classes for building .NET applications using MongoDB as a database. It includes base Dtos, base Entities, and base Repositories to expedite domain-driven development.

Usage

First, you have to install this package via Nuget or .NET CLI.

If you're using Package Manager Console:

Install-Package DotnetBoilerplate.Components.Domain.MongoDb

Or if you're using the .NET CLI:

dotnet add package DotnetBoilerplate.Components.Domain.MongoDb

Now, in your Program.cs file, add the dependency for the repository interfaces:


var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;

// other dependencies
builder.Services.AddMongoDb(configuration);

Or if you have a Startup.cs file, add in your Configure Services method:

// other dependencies

services.AddMongoDb(Configuration);

If you having trouble, see the TestApi Playground Startup.cs for more details.

Now, in your appsettings.json add the MongoDB settings

"MongoSettings": {
   "DatabaseName": "your-database-name",
   "ConnectionString": "your-database-connection-string"
}, 

You are now able to use the package.

BaseDto

To create a domain-specific Dto, inherit from BaseDto and implement the Validate() method to perform custom validation for the Dto.


using DotnetBoilerplate.Components.Domain.MongoDb.Dtos.Base;

public class TestDto : BaseDto
{
    public string TestString { get; set; }

    public override void Validate()
    {
        if(string.IsNullOrEmpty(TestString))
        {
            AddNotification("Error", "TestString is required.");
        }                        
    }
}

If you prefer (I do), you can call an Abstract Validator class on the Validate method

public class TestDtoContract : AbstractValidator<TestDto>
{
    public TestDtoContract()
    {
        RuleFor(dto => dto.TestString)
            .NotEmpty()
            .WithMessage("Cannot be null or empty");
    }
}
public class TestDto : BaseDto
{
    public string TestString { get; set; }

    public override void Validate()
    {
        var contract = new TestDtoContract();
        var validationResult = contract.Validate(this);

        AddNotifications(validationResult);                    
    }
}

BaseEntity

To create a domain-specific Entity, inherit from BaseEntity and implement the Validate() method to perform a custom validation.


using DotnetBoilerplate.Components.Domain.MongoDb.Entities.Base;

namespace TestApi.Domain.Entities
{
    public class Test : BaseEntity
    {
        public Test(string testString)
        {
            TestString = testString;
        }

        public string TestString { get; private set; }

        public override void Validate()
        {
            // Validation like BaseDto above
        }
    }
}

BaseRepository

To create domain-specific repository interfaces for MongoDB, inherit from IBaseWriteRepository<TEntity> or BaseReadRepository<TEntity> depending of your needs. Implement any specific repository methods and logic as needed.

public interface ITestApiWriteRepository : IBaseWriteRepository<Test>
{
    // other methods
}
public interface ITestApiReadRepository : IBaseReadRepository<Test>
{
    // other methods
}

Conclusion

The DotnetBoilerplate.Components.Domain.MongoDB package provides a set of essential base classes and interfaces to streamline the development of .NET applications that use MongoDB as a database. This package is designed to expedite domain-driven development by offering foundational components for building data transfer objects (DTOs), domain entities, and MongoDB repositories.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated