MongoDB.Extensions.Repository 1.0.0

Repository pattern for the official .NET Core MongoDB driver and configured with Microsoft.Extensions.DependencyInjection

There is a newer version of this package available.
See the version list below for details.
Install-Package MongoDB.Extensions.Repository -Version 1.0.0
dotnet add package MongoDB.Extensions.Repository --version 1.0.0
<PackageReference Include="MongoDB.Extensions.Repository" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoDB.Extensions.Repository --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NuGet

mongo-repository

Repository pattern for the official MongoDB .NET Core driver.

Installation

The package is available on NuGet.

dotnet add package MongoDB.Repository

Basic Usage

For basic, generic access, inject IMongoRepository&lt;TEntity&gt; into your services for example:

public class SomeService
{
    private readonly IMongoRepository<SomeEntity> _repository;

    public SomeService(IMongoRepository<SomeEntity> repository)
    {
        _repository = repository;
    }

    public async Task<SomeEntity> GetSomeDataAsync(string id) => await _repository.GetAsync(id);
}

By default, collections will be named in lower snake_case.

Configuration

Configuration is easy in ASP.Net Core applications. In Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    var assembly = typeof(Startup).Assembly;
    services.AddMongoRepositories(_configuration.GetConnectionString("mongo"))
            .FromAssembly(assembly) // Registers all classes that implement IMongoRepository<TEntity>
            .WithIndexesFromAssembly(assembly); // Registers all classes that implement MongoIndexProfile<TEntity>
}

Indexes

Configured indexes will be created the first time that a collection is accessed.
To configure indexes, implement MongoIndexProfile&lt;TEntity&gt; for example, to create an ascending, case insensitive, unique index on SomeEntity.Name called name_unique:

public class SomeIndexProfile : MongoIndexProfile<SomeEntity>
{
    public SomeIndexProfile()
    {
        Add("name_unique", IndexKeys.Ascending(x => x.Name), o => o.Unique().WithCaseInsensitiveCollation());
    }
}

NuGet

mongo-repository

Repository pattern for the official MongoDB .NET Core driver.

Installation

The package is available on NuGet.

dotnet add package MongoDB.Repository

Basic Usage

For basic, generic access, inject IMongoRepository&lt;TEntity&gt; into your services for example:

public class SomeService
{
    private readonly IMongoRepository<SomeEntity> _repository;

    public SomeService(IMongoRepository<SomeEntity> repository)
    {
        _repository = repository;
    }

    public async Task<SomeEntity> GetSomeDataAsync(string id) => await _repository.GetAsync(id);
}

By default, collections will be named in lower snake_case.

Configuration

Configuration is easy in ASP.Net Core applications. In Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    var assembly = typeof(Startup).Assembly;
    services.AddMongoRepositories(_configuration.GetConnectionString("mongo"))
            .FromAssembly(assembly) // Registers all classes that implement IMongoRepository<TEntity>
            .WithIndexesFromAssembly(assembly); // Registers all classes that implement MongoIndexProfile<TEntity>
}

Indexes

Configured indexes will be created the first time that a collection is accessed.
To configure indexes, implement MongoIndexProfile&lt;TEntity&gt; for example, to create an ascending, case insensitive, unique index on SomeEntity.Name called name_unique:

public class SomeIndexProfile : MongoIndexProfile<SomeEntity>
{
    public SomeIndexProfile()
    {
        Add("name_unique", IndexKeys.Ascending(x => x.Name), o => o.Unique().WithCaseInsensitiveCollation());
    }
}

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.57 673 12/31/2019
2.0.53 124 12/31/2019
1.0.44 722 6/9/2018
1.0.40 345 4/8/2018
1.0.36 481 4/8/2018
1.0.32 468 4/7/2018
1.0.28 456 3/31/2018
1.0.24 468 3/31/2018
1.0.0 440 3/31/2018
Show less