Class DataService
This implementation of IDataService caches data under all Types possible. Once data has been added you can access it via any base or interface Types that also implement IData. This service does not handle any direct loading or unloading operations for data, however by passing a ISingleDataProvider<TOutputData> or IMultipleDataProvider<TOutputData> you can have the provider load the data asynchronously when this attempts to retrieve it.
Inherited Members
Namespace: IdleKit.Core
Assembly: cs.temp.dll.dll
Syntax
public class DataService : BindingService, IDataService, IService, IInjectable
Fields
_actionService
Declaration
protected IActionService _actionService
Field Value
Type | Description |
---|---|
IActionService |
_dataTypeIdCache
Declaration
protected Dictionary<Type, List<string>> _dataTypeIdCache
Field Value
Type | Description |
---|---|
Dictionary<Type, List<String>> |
_resolver
Declaration
protected IResolver _resolver
Field Value
Type | Description |
---|---|
IResolver |
Methods
AddData(IData)
Add one IData object.
Declaration
public virtual void AddData(IData data)
Parameters
Type | Name | Description |
---|---|---|
IData | data | The IData object to add. |
AddData(IDataProvider, Action<List<IData>>)
Adds data from a IDataProvider. Supports ISingleDataProvider<TOutputData> and IMultipleDataProvider<TOutputData>. This will attempt to get the data asynchronously and broadcast a callback when the data has been added. This stores IData objects under every possible type and interface that implements or extends IData for the supplied data. This allows for looking up the data by any relevant Type.
Declaration
public virtual void AddData(IDataProvider dataProvider, Action<List<IData>> onComplete)
Parameters
Type | Name | Description |
---|---|---|
IDataProvider | dataProvider | The IDataProvider to get the data from. |
Action<List<IData>> | onComplete | Broadcast when the data has been added. |
AddData(IEnumerable<IData>)
This stores IData objects under every possible type and interface that implements or extends IData for the supplied data. This allows for looking up the data by any relevant Type.
Declaration
public virtual void AddData(IEnumerable<IData> datas)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IData> | datas | One or more IData objects to add. |
AddDataInternal(IData[])
This is the central add method. All other add data methods add data through this method.
Declaration
protected virtual void AddDataInternal(params IData[] datas)
Parameters
Type | Name | Description |
---|---|---|
IData[] | datas |
CleanupService()
Declaration
protected override void CleanupService()
Overrides
GetAllData(Type)
Returns all IData objects under a specific Type.
Declaration
public virtual List<IData> GetAllData(Type dataType)
Parameters
Type | Name | Description |
---|---|---|
Type | dataType | The Type of IData objects to get. |
Returns
Type | Description |
---|---|
List<IData> |
GetAllData(Type, IEnumerable<String>)
Declaration
public virtual List<IData> GetAllData(Type dataType, IEnumerable<string> ids)
Parameters
Type | Name | Description |
---|---|---|
Type | dataType | The Type of IData objects to get. |
IEnumerable<String> | ids | The ids to retrieve data for. |
Returns
Type | Description |
---|---|
List<IData> |
GetAllData(Type, Func<IData, Boolean>)
Returns all IData objects under a specific Type that meets the predicate criteria.
Declaration
public virtual List<IData> GetAllData(Type dataType, Func<IData, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Type | dataType | The Type of IData objects to get. |
Func<IData, Boolean> | predicate | The criteria that must be met by the IData objects. |
Returns
Type | Description |
---|---|
List<IData> |
GetAllData<TData>()
Returns all IData objects under a specific Type.
Declaration
public virtual List<TData> GetAllData<TData>()
where TData : class, IData
Returns
Type | Description |
---|---|
List<TData> |
Type Parameters
Name | Description |
---|---|
TData | The Type of IData objects to get. |
GetAllData<TData>(IEnumerable<String>)
Declaration
public virtual List<TData> GetAllData<TData>(IEnumerable<string> ids)
where TData : class, IData
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<String> | ids |
Returns
Type | Description |
---|---|
List<TData> |
Type Parameters
Name | Description |
---|---|
TData | The Type of IData objects to get. |
GetAllData<TData>(Func<TData, Boolean>)
Declaration
public virtual List<TData> GetAllData<TData>(Func<TData, bool> predicate)
where TData : class, IData
Parameters
Type | Name | Description |
---|---|---|
Func<TData, Boolean> | predicate |
Returns
Type | Description |
---|---|
List<TData> |
Type Parameters
Name | Description |
---|---|
TData |
GetData(Type)
Returns the first IData object found in the cache under the specified Type.
Use overloads that take Id if possible for better performance.
Declaration
public virtual IData GetData(Type dataType)
Parameters
Type | Name | Description |
---|---|---|
Type | dataType | The Type of IData object to get. |
Returns
Type | Description |
---|---|
IData |
GetData(Type, Func<IData, Boolean>)
Returns the first IData object found in the cache under the specified Type that meets the predicate criteria.
Use overloads that take Id if possible for better performance.
Declaration
public virtual IData GetData(Type dataType, Func<IData, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Type | dataType | The Type of IData object to get. |
Func<IData, Boolean> | predicate | The criteria that must be met by the IData object. |
Returns
Type | Description |
---|---|
IData |
GetData(Type, String)
Declaration
public virtual IData GetData(Type dataType, string id)
Parameters
Type | Name | Description |
---|---|---|
Type | dataType | The Type of IData object to get. |
String | id | The Id associated with the object to get. |
Returns
Type | Description |
---|---|
IData |
GetData<TData>()
Returns the first IData object found in the cache under the specified Type.
Use overloads that take Id if possible for better performance.
Declaration
public virtual TData GetData<TData>()
where TData : class, IData
Returns
Type | Description |
---|---|
TData |
Type Parameters
Name | Description |
---|---|
TData | The Type of IData object to get. |
GetData<TData>(Func<TData, Boolean>)
Returns the first IData object found in the cache under the specified Type that meets the predicate criteria.
Use overloads that take Id if possible for better performance.
Declaration
public virtual TData GetData<TData>(Func<TData, bool> predicate)
where TData : class, IData
Parameters
Type | Name | Description |
---|---|---|
Func<TData, Boolean> | predicate |
Returns
Type | Description |
---|---|
TData |
Type Parameters
Name | Description |
---|---|
TData |
GetData<TData>(String)
Declaration
public virtual TData GetData<TData>(string id)
where TData : class, IData
Parameters
Type | Name | Description |
---|---|---|
String | id | The Id associated with the object to get. |
Returns
Type | Description |
---|---|
TData |
Type Parameters
Name | Description |
---|---|
TData | The Type of IData object to get. |
InitializeService()
Declaration
protected override void InitializeService()
Overrides
Inject(IResolver)
Declaration
public override void Inject(IResolver resolver)
Parameters
Type | Name | Description |
---|---|---|
IResolver | resolver |
Overrides
RemoveAllData()
This removes IData objects under every possible type and interface that implements or extends IData for the supplied data.
Declaration
public virtual void RemoveAllData()
RemoveAllData(Type)
Remove all IData objects keyed by a specific Type.
Declaration
public virtual void RemoveAllData(Type dataType)
Parameters
Type | Name | Description |
---|---|---|
Type | dataType | The Type to remove the objects from. |
RemoveAllData<TData>()
Remove all IData objects keyed by a specific Type.
Declaration
public virtual void RemoveAllData<TData>()
where TData : class, IData
Type Parameters
Name | Description |
---|---|
TData | The Type to remove the objects from. |
RemoveData(IData)
Remove one IData object.
Declaration
public virtual void RemoveData(IData data)
Parameters
Type | Name | Description |
---|---|---|
IData | data | The IData object to remove. |
RemoveData(IDataProvider, Action)
Removes data from a IDataProvider. Supports ISingleDataProvider<TOutputData> and IMultipleDataProvider<TOutputData>. This will attempt to get the data asynchronously and broadcast a callback when the data has been removed. Since the data is stored in this Service by reference you should not reload the data in the provider. Providers should cache the loaded data so equality checks pass.
Declaration
public virtual void RemoveData(IDataProvider dataProvider, Action onComplete)
Parameters
Type | Name | Description |
---|---|---|
IDataProvider | dataProvider | The IDataProvider to get the data from. |
Action | onComplete | Broadcast when the data has been removed. |
RemoveData(IEnumerable<IData>)
Removes one or more IData objects that can be of varied Types.
Declaration
public virtual void RemoveData(IEnumerable<IData> datas)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IData> | datas | One or more IData objects to remove. |
RemoveDataInternal(IData[])
This is the central remove method. All other remove data methods remove data through this method.
Declaration
protected virtual void RemoveDataInternal(params IData[] datas)
Parameters
Type | Name | Description |
---|---|---|
IData[] | datas |