Spinit.CosmosDb 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Spinit.CosmosDb --version 3.0.0
NuGet\Install-Package Spinit.CosmosDb -Version 3.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Spinit.CosmosDb" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Spinit.CosmosDb --version 3.0.0
#r "nuget: Spinit.CosmosDb, 3.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Spinit.CosmosDb as a Cake Addin
#addin nuget:?package=Spinit.CosmosDb&version=3.0.0

// Install Spinit.CosmosDb as a Cake Tool
#tool nuget:?package=Spinit.CosmosDb&version=3.0.0

Spinit.CosmosDb

Lightweight CosmosDb wrapper

Install

Package Manager:

PM> Install-Package Spinit.CosmosDb

.NET CLI:

> dotnet add package Spinit.CosmosDb

Usage

Define a database model

Automatic initialization

public class MyEntity : ICosmosEntity
{
    public string Id { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
}

/*
 Name of the cosmos database, optional.
 If not provided, name of class will be used (MyDatabase in this case).
*/
[DatabaseId("FooDatabase")]
public class MyDatabase : CosmosDatabase
{
    public MyDatabase(DatabaseOptions<MyDatabase> options)
        : base(options)
    { }

    /*
    Name of the cosmos collection, optional.
    If not provided, name of class will be used (MyEntities in this case).
    */
    [CollectionId("FooCollection")]
    public ICosmosDbCollection<MyEntity> MyEntities { get; private set; }
}

Manual initialization

public class MyEntity : ICosmosEntity
{
    public string Id { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
}

public class MyDatabase : CosmosDatabase
{
    public MyDatabase(DatabaseOptions<MyDatabase> options)
        : base(options, initialize: false)
    { }

    public ICosmosDbCollection<MyEntity> MyEntities { get; private set; }

    protected override void OnModelCreating(DatabaseModelBuilder<MyDatabase> modelBuilder)
    {
        modelBuilder.DatabaseId("FooDatabase");

        modelBuilder.Collection(x => x.MyEntities)
            .CollectionId("FooCollection");
    }
}

Add to services (IoC):

var myConnectionString = configuration.GetConnectionString("CosmosDb");

services
    ...
    // This will register the database type and all it's collections
    .AddCosmosDatabase<MyDatabase>(options => options.UseConnectionString(myConnectionString))
    ...
    ;

Inject and use:

public class MyController : ControllerBase
{
    private readonly ICosmosDbCollection<MyEntity> _collection;

    public MyController(ICosmosDbCollection<MyEntity> collection)
    {
        _collection = collection;
    }

    [HttpGet]
    public Task<SearchResponse<MyEntity>> List(string query)
    {
        var searchRequest = new SearchRequest<MyEntity>
        {
            Query = query
        };
        return _collection.SearchAsync(searchRequest);
    }

    [HttpGet("{id}")]
    public Task<MyEntity> Get(string id)
    {
        return _collection.GetAsync(id);
    }

    [HttpPost]
    public Task Upsert(MyEntity input)
    {
        return _collection.UpsertAsync(input);
    }
}

License

MIT License

Copyright (c) 2019- Spinit AB

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product 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.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 1,177 7/14/2023
3.0.0 2,233 5/6/2022
2.2.0 5,085 11/22/2021
2.1.0 2,306 5/17/2021
2.0.3 661 4/14/2021
2.0.2 433 4/14/2021
2.0.1 453 4/13/2021
2.0.0 2,093 10/7/2020
2.0.0-rc7 1,187 8/27/2020
2.0.0-rc6 325 8/25/2020
2.0.0-rc4 461 5/26/2020
2.0.0-rc3 417 5/6/2020
2.0.0-rc2 353 4/30/2020
2.0.0-rc1 344 4/30/2020
1.1.0-rc5 496 11/12/2019
1.1.0-rc4 1,810 9/27/2019
1.1.0-rc3 953 8/13/2019
1.1.0-rc2 460 7/5/2019
1.1.0-rc1 417 5/8/2019
1.0.0 729 5/6/2019
1.0.0-rc1 424 5/3/2019
0.0.9 664 5/2/2019
0.0.8 1,050 4/24/2019
0.0.7 663 4/23/2019
0.0.6 563 4/18/2019
0.0.5 618 4/15/2019
0.0.4 637 3/26/2019
0.0.3 583 3/21/2019
0.0.2 609 3/11/2019
0.0.1 701 2/20/2019