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