05.-Data-Framework
Data plays an important role in data-centric applications. In this type of applications, you usually retrieve data from remote-server, work with it inside the application, display it in UI components, and finally send data to the remote server. Sometimes you need to store some data on local storage and other storages like that, invalidate it on the specific condition and...
Narik Data Service has two main concepts.
Data Provider
Data Storage
Data Provider
Data Provider is a class that provides data for the system. It must inherit DataProvider interface. You can have a lot of DataProvider in your application that each of then provides data in a different way.
Currently, there are six DataProviders in Narik.
RemoteDataProvider
LocalStorageDataProvider
SessionStorageDataProvider
MemoryDataProvider
StaticDataProvider
ClientStorageDataProvider
Data Storage
Data Storage is a class that can store data for the system. It must inherit DataStorage interface. You can have a lot of dataStorage in your application that each of then stores data in a different way and different location. Every DataStorage is also DataProvider, because DataStorage interface extends DataProvider interface.
Currently, there are four DataStorages in Narik.
LocalStorageDataProvider
SessionStorageDataProvider
MemoryDataProvider
ClientStorageDataProvider
These four classes concurrently are DataProvider and DataStorage but other two classes (RemoteDataProvider and StaticDataProvider) are only dataProvider because they don't store data.
Data Provider Service
DataProviderServices acts as a manager for all DataProviders. it collects all DataProviders and manages them. Many times it's better you work with DataProviderServices rather than with DataProvider.
Data Storage Service
DataStorageServices acts as a manager for all DataStorages. it collects all DataStorages and manages them. Many times it's better you work with DataStorageServices rather than with DataStorage.
How It Works
As said before Narik provides some DataProvider and DataStorage. But you can add new DataProviders and DataStorages.
Add New DataProvider 1. Create a class that implements DataProvider. 2. Provide it in your module providers as DATA_PROVIDER.
Example:
```typescript import {DataProvider,DataInfo} from "@narik/infrastructure";
Add New DataStorage 1. Create a class that implements DataStorage. 2. Provide it in your module providers as DATA_STORAGE.
Example:
```typescript import {DataStorage,DataInfo} from "@narik/infrastructure";
Use Data Provider To Use DataProvider, you can work with specified DataProvider or use DataProviderService. Narik suggests you use DataProviderService.
Example 1:
Example 1:
Use Data Storage To Use DataStorage, you can work with specified DataStorage or use DataStorageService. Narik suggest you to use DataStorageService. Don't forget every DataStorage is also DataProvider and can be used like DataProvider.
Example
Last updated