Git Product home page Git Product logo

xamentitymanager's Introduction

XamEntityManager

Xamarin client service for PHPAngular server https://github.com/emeric0101/PHPAngular It includes a dependency injection.

Installation

  1. Add the package tu nuget

  2. Implement the interface : ISQLite.cs : (you need to install sqlite.net https://github.com/oysteinkrog/SQLite.Net-PCL for each plateform)

    public interface ISQLite
    {
        SQLiteConnection GetConnection();
    }
  1. Implement the user interface, the user class must derive from XamEntityManager.Entity.AEntity
    public interface IUser
    {
        string Sid { get; set; }
    }
  1. In your App.cs, you have to create the Depedency Injector : (User is the implementation of IUser)
diService = new DiService("https://REST_URL/", typeof(User));

Usage

DI

To use the depedency injector, you have to use it each time you create a page :

            app.MainPage = diService.createPage(typeof(DmoApp.Login));

In each class which is injected, you can provided an array to inject other classes :

		public static Type[] inject =  {
            typeof(MY OTHER CLASS SERVICE 1),
            typeof(MY OTHER CLASS SERVICE 2)
        };
        // then in the constructor : 
    public MyClass(MY OTHER CLASS SERVICE 1 myObj1, MY OTHER CLASS SERVICE 2 myObj2)
    {
    
    }

Repository service

Each data model you need must be declared with a class which derived from XamEntityManager.Entity.AEntity. To get data from the server, you have some method from the repository service. First, don't forget to inject it (typeof(XamEntityManager.Service.RepositoryService) Then, you can use from the repository object : (like phpangular server side)

  • T obj = await findById(int id)
  • List objs = await findAll
  • List objs = await findSome(string method, int id, Dictionary<string, dynamic> args)

EntityManager

When you have create a model and you want to save it, you use the EntityManager First, inject it typeof(XamEntityManager.Service.EntityManager) Then, use it to persist the model :

  entityManager.persist(MY MODEL);
  await entityManager.flush(); // Synchronise the persist cache to the server

User login

To login a user, inject LoginService then

bool result = await login<T>(string mail, string password, bool stay)
await logout() // to logout...
IUser user = await getUser() // get the logged user (or null if not logged)

Enjoy !

xamentitymanager's People

Contributors

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