iMongoDbRepository 1.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package iMongoDbRepository --version 1.3.1                
NuGet\Install-Package iMongoDbRepository -Version 1.3.1                
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="iMongoDbRepository" Version="1.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add iMongoDbRepository --version 1.3.1                
#r "nuget: iMongoDbRepository, 1.3.1"                
#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 iMongoDbRepository as a Cake Addin
#addin nuget:?package=iMongoDbRepository&version=1.3.1

// Install iMongoDbRepository as a Cake Tool
#tool nuget:?package=iMongoDbRepository&version=1.3.1                

iMongoDbRepository

Requires .Net Standard 2.1+

Nuget Package

PM> Install-Package iMongoDbRepository

URL: https://www.nuget.org/packages/iMongoDbRepository

Usage

All entities must be derived from an interface called IMongoDbItem. This interface contains a mandatory field called _id and some extra data needed.

Let's say you have an object called person as follows;

public class Person
{
    public string Name { get; set; }
    public string Surname { get; set; }
}

Then you create an entity class for the person object just to satisfy IMongoDbItem interface.

public class PersonEntity: Person, IMongoDbItem
{
    public string _id { get; set; }
    public DateTime CreatedOn { get; set; }
    public DateTime ModifiedOn { get; set; }
    public bool Deleted { get; set; }
}

First create a repository class;

public class PersonRepo : MongoDbRepository<PersonEntity>
{

} 
static void Main(string[] args)
{
    //Instantiate your repo.
    var personRepo = new PersonRepo();

    //Configure it
    personRepo.Configure(new DbConfiguration()
    {
        ConnectionString = "mongodb://localhost:27017",//your MondoDb connection string
        DbName = "iTest",
        Collection = "iCollection"
    });

    //Your object is ready
    var person = new PersonEntity();

    //Insert person object
    personRepo.Insert(person);

    //Retreave all items in the db
    var all = personRepo.All();
}

First create your interface. If you will not add extra methods, just create an empty one. Then, derive your class from the interface and MongoDbRepository abstract class as follows. By this way, when this class is instanciated, methods on the abstract class will be called.

Usage with Dependancy Injection

public class IPersonRepo : IRepository<PersonEntity>
{

} 

public class PersonRepo : MongoDbRepository<PersonEntity>, IPersonRepo
{

} 

Sample container configuration:

container.For<IPersonRepo>().Use<PersonRepo>();

When you instanciate or inject the IPersonRepo, you have the repository. However, do not forget to configure it by calling Configure method.


personRepo.Configure(new DbConfiguration()
    {
        ConnectionString = "mongodb://localhost:27017",//your MondoDb connection string
        DbName = "iTest",
        Collection = "iCollection"
    });
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 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
1.5.1 343 7/1/2023
1.5.0 205 6/16/2023
1.4.2 881 3/14/2019
1.4.1 743 2/11/2019
1.3.1 742 2/1/2019
1.3.0 834 1/8/2019
1.2.0 933 9/5/2018
1.1.0 965 8/16/2018