iMongoDbRepository 1.3.1
See the version list below for details.
dotnet add package iMongoDbRepository --version 1.3.1
NuGet\Install-Package iMongoDbRepository -Version 1.3.1
<PackageReference Include="iMongoDbRepository" Version="1.3.1" />
paket add iMongoDbRepository --version 1.3.1
#r "nuget: iMongoDbRepository, 1.3.1"
// 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 | Versions 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. |
-
.NETCoreApp 2.1
- MongoDB.Driver (>= 2.7.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.