Xamarin client service for PHPAngular server https://github.com/emeric0101/PHPAngular It includes a dependency injection.
-
Add the package tu nuget
-
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();
}
- Implement the user interface, the user class must derive from XamEntityManager.Entity.AEntity
public interface IUser
{
string Sid { get; set; }
}
- 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));
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)
{
}
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)
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
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 !