iMongoDbRepository 1.1.0

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

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

iMongoDbRepository

Usage

All entities must be derived from iMongoDbItem interface. This interface contains _id and some extra data needed.

iMongoDbItem:

public interface IMongoDbItem
{
    string _id { get; set; }
    DateTime CreatedOn { get; set; }
    DateTime ModifiedOn { get; set; }
    bool Deleted { get; set; }
}

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

public class Person: IMongoDbItem
{
    public string Name { get; set; }
    public string Surname { get; set; }
    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<Person>
{

} 
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 Person();

    //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 : MongoDbRepository<Person>
{

} 

public class PersonRepo : IPersonRepo, MongoDbRepository<Person>
{

} 

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