Giter Site home page Giter Site logo

tallalkazmi / tk.mongodb.repository.netcore Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 31 KB

Repository pattern implementation of MongoDB collections using LINQ with optional Dependency Tracking in .NET Standard 2.0.

License: MIT License

C# 100.00%

tk.mongodb.repository.netcore's Introduction

TK.MongoDB.Repository.NetCore

Nuget Nuget Azure DevOps builds Azure DevOps tests Azure DevOps releases

Repository pattern implementation of MongoDB collections using LINQ with optional Dependency Tracking in .NET Standard 2.0.

Usage

Connection

Connection string should be provided by using Connection class. Inject this class in the following manner if you are using DI:

services.AddTransient(x => new Connection(Configuration.GetConnectionString("DefaultConnection")));

Settings

  1. Global collection settings can be applied by using Settings.Configure<T> where T is collection model implementing IDbModel. This method accepts:

    • Connection (for connection string)
    • Expire After (for ExpiryAfterSeconds index)
    • Create Collection Options ()

Use this method with a specific collection model, make sure this method is called once for each application run.

  1. If you intend to use Dependency Tracking, you can specify commands to not track by setting the Settings.NotTrackedCommands, by default the following commands are not not tracked:

    • isMaster
    • buildInfo
    • getLastError
    • saslStart
    • saslContinue
    • listIndexes

Collections

Create a collection model implementing IDbModel interface for use in repository. The name of this model will be used as collection name in MongoDB. For example:

public class Activity : IDbModel
{
    public ObjectId Id { get; set; }
    public bool Deleted { get; set; }
    public DateTime CreationDate { get; set; }
    public DateTime? UpdationDate { get; set; }
    public string Name { get; set; }
}

Dependency Tracking

To use dependency tracking implement the IDependencyTracker interface to meet your needs. For example:

public class DependencyTracker : IDependencyTracker
{
	public void Dependency(string name, string description, bool success, TimeSpan duration)
    {
    	Console.WriteLine($"{name}-{description}-{success}-{duration}");
    }
}

Examples & Tests

Refer to TK.MongoDB.Test project for all Unit Tests and examples.

tk.mongodb.repository.netcore's People

Contributors

tallalkazmi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.