Git Product home page Git Product logo

loki-aspnetcore's Introduction

loki-aspnetcore

asp.net core translation layer for interfacing with loki-nodeservice

Overview

This library contains generic reusable c# abstractions for interfacing with :

  • LokiDatabase
  • LokiCollections
  • Query Chaining and Transforms
  • loki-nodeservice statistics and collection information

Nuget

This library has been published as loki-aspnetcore on nuget so applications wishing to use this library should add a reference in their csproj file to :

    <PackageReference Include="loki-aspnetcore" Version="1.0.0" />

Usage

Note that in order to use this library, you will need an npm library (loki-nodeservice) which we demonstrate more fully in our loki-aspnetcore-example repository.

Generally you will need to bootstrap logic into each Controller for interfacing with loki-aspnetcore and its node.js library via a Controller constructor such as :

        private LokiDatabaseConfiguration _demoServiceConfiguration;
        
        public UserController(IHostingEnvironment env)

        {
            _env = env;

            _demoServiceConfiguration = new LokiDatabaseConfiguration(
                "./node_modules/loki-nodeservice/lokiservice.js", 
                env.ContentRootPath.Replace("\\", "/") + "/nodesvcs/demo1-service.init.js", 
                "./dbinstances/demo-1.db"
            );            
        }
        

That somewhat ugly bit of path resolution should suffice for abstraction of the loki-nodeservice node module as well as your custom service initializer (also demonstrated in our loki-aspnetcore-example). Your service initializer will be called by the loki-nodeservice for defining/creating/spinning up instanc(es) of the databases you initialize in your initializer. loki-nodeservice, in turn, will be called by nodeservices, which in turn, will be called by asp.net nodeservices, which is called by your controller. The above definition of a global LokiDatabaseConfiguration object will contain most of the pathing 'glue' needed for that to work.

Having established that configuration object and your c# concrete classes, you might have controller actions which query a collection such as this view action :

        public async Task<IActionResult> Index([FromServices] INodeServices nodeServices)
        {
            LokiDatabase db = new LokiDatabase(nodeServices, _demoServiceConfiguration);

            List<User> result = await db.Find<User>("users");

            return View(result);
        }

Note the asp.net nodeservices dependency injection and our configuration object are passed to resolve a LokiDatabase instance which we can use to query. The creation of the LokiDatabase is for establishing configuration only for subsequent method invocations to be able to resolve how to address the node service.

Detailed Example

Please see our for an example on how you might use this library, along with loki-nodeservice npm package and asp.net nodeservices to completely host, query, and obtain statistic on lokijs database(s).

loki-aspnetcore's People

Contributors

obeliskos 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.