1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/code-Institutes-Apteryx.MongoDB.Driver.Extend

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
В этом репозитории не указан файл с открытой лицензией (LICENSE). При использовании обратитесь к конкретному описанию проекта и его зависимостям в коде.
Клонировать/Скачать
Внести вклад в разработку кода
Синхронизировать код
Отмена
Подсказка: Поскольку Git не поддерживает пустые директории, создание директории приведёт к созданию пустого файла .keep.
Loading...
README.md

Расширение для MongoDB.Driver

Установка

Install-Package Apteryx.MongoDB.Driver.Extend

Пример использования 1:

public class Account : BaseMongoEntity
{
    public string Name { get; set; }
    public string Mobile { get; set; }
}

public class MyDbService : MongoDbService
{
    public MyDbService(IOptionsMonitor<MongoDBOptions> options) : base(options) {}
    public IMongoCollection<Account> Account => _database.GetCollection<Account>("Account");
}

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMongoDB<MyDbService>(options =>
        {
            options.ConnectionString = Configuration.GetConnectionString("MongoDbConnection");
        });
        //.....................
    }
}

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    private readonly MyDbService db;

    public ValuesController(IMongoDbService db)
    {
        this.db = (MyDbService)db;
    }

    // GET api/values
    [HttpGet]
    public ActionResult<IEnumerable<string>> Get()
    {
        db.Account.InsertOne(new Account() { Name = "Иванов", Mobile = "+79123456789" });
        return new string[] { "значение1", "значение2" };
    }
}

Пример использования 2:

public class Account : BaseMongoEntity
{
    public string Name { get; set; }
    public string Mobile { get; set; }
}

public class MyDbService : MongoDbService
{
    public MyDbService(string conn) : base(conn) {}

    public IMongoCollection<Account> Account => _database.GetCollection<Account>("Account");
}

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    // GET api/values
    [HttpGet]
    public ActionResult<IEnumerable<string>> Get()
    {
        var db = new MyDbService("mongodb://user:pwd@xxx.xxx.xxx.xxx:27017/testdb?authSource=admin");
        db.Account.InsertOne(new Account() { Name = "Петров", Mobile = "+79123456780" });
        return new string[] { "значение1", "значение2" };
    }
}

Комментарии ( 0 )

Вы можете оставить комментарий после Вход в систему

Введение

Расширение для MongoDB.Driver. Развернуть Свернуть
Отмена

Обновления

Пока нет обновлений

Участники

все

Недавние действия

Загрузить больше
Больше нет результатов для загрузки
1
https://api.gitlife.ru/oschina-mirror/code-Institutes-Apteryx.MongoDB.Driver.Extend.git
git@api.gitlife.ru:oschina-mirror/code-Institutes-Apteryx.MongoDB.Driver.Extend.git
oschina-mirror
code-Institutes-Apteryx.MongoDB.Driver.Extend
code-Institutes-Apteryx.MongoDB.Driver.Extend
master