Skip to content

xDelivered-Patrick/xDelivered.Essentials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 

Repository files navigation

xDelivered Common

Install-Package xDelivered.Common

What is this?

Common classes to help with general .Net development

xDelivered MVC

Install-Package xDelivered.Mvc

What is this?

Common classes to help with MVC development

xDelivered XDb Provider

Install-Package xDelivered.Essentials.DocDb

What is this?

Data access service combining CosmosDb and Redis for optimised latency and NoSQL relationships

Why is this useful?

  • Query via cosmosDb for enumerable and complex queries
  • Pull from Redis for simple object grabs
  • Optimised latency for type of query, leveraging Redis or Cosmos depending on requirements
  • Framework allowing relationships between NoSQL document types

Upsert documents to Redis and CosmosDb in one line

//use DI for this in production
var db = new XDbProvider("redisConnectionString", new CosmosContext("cosmosEndpoint", "cosmosKey", "cosmosDb", "mainCollection"));

//insert into cosmos and redis
await db.UpsertDocumentAndCache(new User {FirstName = "Billy", LastName = "Bob", Age = 35});

Pull single object with cache fallback

//pulls from database (tries Redis first, falls back to CosmosProvider)
var user = await db.GetObjectAsync<User>("userId");

Push to cache only with expiry

_db.SetObjectOnlyCache(user, TimeSpan.FromHours(3));

Automagically handles ID creation, Created/Updated, Soft deletes

{
  "id": "Billy Bob",
  "FirstName": "Billy",
  "LastName": "Bob",
  "FullName": "Billy Bob",
  "Age": 35,
  "Created": "2017-05-23T11:05:02.6059438Z",
  "Updated": null,
  "Type": "User",
  "IsDeleted": false
}

Single object location - uses object links to define noSQL relationships

public class User : DatabaseModelBase
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string FullName => $"{FirstName} {LastName}";
    public int Age { get; set; }

    public List<ObjectLink<Tournament>> CompletedTournaments { get; set; } = new List<ObjectLink<Tournament>>();
}

//add link between user and tournament
user.CompletedTournaments.Add(new ObjectLink<Tournament>(completedTournament));

Which stores JSON with foreign relationship link

{
  "Name": "Andy Murray",
  "CompletedTournaments": [
    {
      "Link": "nhwcvpzjf05tyj4rjmq",
      "Identifier": "nhwcvpzjf05tyj4rjmq"
    }
  ]
}

Now resolve foreign relationship in single line via object resolver. Leverages Memory/Redis/Cosmos for optimal latency

//now pull tournament from user object via memory/redis/cosmosDb (order of query)
Tournament tourney = user.CompletedTournaments.First().Resolve();

Override key creation to achieve object upsert persistance instead of using short GUID

public class User : DatabaseModelBase
{
    public override string Id => $"{FirstName} {LastName}";

    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Redis2

How do I run the samples?

You'll need local running instances of Redis and Cosmos.

  1. Install chocolatly

    https://chocolatey.org/install

  2. Install redis

    choco install redis

  3. Install CosmosDb locally

    choco install azure-documentdb-emulator

  4. Run!

Recommended tools

Hire me

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages