Interface ITypedApi
This API describes objects with a TypedApi.
[WorkInProgressApi("Still WIP v20")]
public interface ITypedApi
Remarks
This is usually only relevant when using the ITypedApiService which will get you a standalone object with this API.
Properties
AllResources
Stack of all Resources in the System, merging Resources of View, App, Site, Global etc. Will retrieve values by priority, with View-Resources being top priority and Preset-Resources being the lowest.
Tip
If you know that Resources come from the App, you should prefer App.Resources instead.
That is faster and helps people reading your code figure out where to change a value.
ITypedStack AllResources { get; }
Property Value
AllSettings
Stack of all Settings in the System, merging Settings of View, App, Site, Global etc. Will retrieve values by priority, with View-Settings being top priority and Preset-Settings being the lowest.
Tip
If you know that Settings come from the App, you should prefer App.Settings instead.
That is faster and helps people reading your code figure out where to change a value.
ITypedStack AllSettings { get; }
Property Value
App
The current App object (with strictly typed Settings/Resources).
Use it to access App properties such as Path or any data in the App.
IAppTyped App { get; }
Property Value
Kit
ServiceKit16 Kit { get; }
Property Value
Link
Link helper object to create the correct links
ILinkService Link { get; }
Property Value
- ILinkService
A ILinkService object.
MyContext
This Context tells you about the environment, such as
- the current User
- the Page
- the View
- the Site
It's supposed to replace direct access to Dnn or Oqtane object in Razor and WebAPI code, allowing hybrid code that works everywhere.
ICmsContext MyContext { get; }
Property Value
Remarks
New in v11.11
MyData
All the data which the current Template received, based on the View configuration. There are a few common scenarios:
- If it's a simple view, then this will just contain streams with the main Item(s) and Header
- If the view expects no data, it will just contain a
Defaultstream containing no items - If the view has a Query behind it, then MyData will have all the streams provided by the Query
IDataSource MyData { get; }
Property Value
MyHeader
The Header-Item belonging to this Template/Module. This data is edited by the user directly on this specific module. In some cases it can also be a pre-set item configured in the View to be used if the user has not added any data himself.
ITypedItem MyHeader { get; }
Property Value
MyItem
The main Item belonging to this Template/Module. This data is edited by the user directly on this specific module. In some cases it can also be a pre-set item configured in the View to be used if the user has not added any data himself.
If this view can have a list of items (more than one) then this contains the first item. To get all the items, see MyItems
ITypedItem MyItem { get; }
Property Value
MyItems
List of all Items belonging to this Template/Module. This data is edited by the user directly on this specific module. In some cases it can also be a pre-set item configured in the View to be used if the user has not added any data himself.
If this view is configured to only have one item, then this list will only contain one item. Otherwise, it will have as many items as the editor added.
IEnumerable<ITypedItem> MyItems { get; }
Property Value
MyPage
Information about the current Page (called Tab in DNN). It's especially useful to get current URL Parameters.
ICmsPage MyPage { get; }
Property Value
MyUser
Information about the current user. It's especially useful to see if the user has any kind of Admin privileges.
ICmsUser MyUser { get; }
Property Value
MyView
View-information such as the view Name, Identity or Edition.
ICmsView MyView { get; }
Property Value
Remarks
New in v12.02
UniqueKey
A unique, random key for the current module. It's recommended for giving DOM elements a unique id for scripts to then access them.
It's generated for every content-block, and more reliable than Module.Id
since that sometimes results in duplicate keys, if the many blocks are used inside each other.
It's generated using a GUID and converted/shortened. In the current version it's 8 characters long, so it has 10^14 combinations, making collisions extremely unlikely. (currently 8 characters)
Tip
To get a unique key which is based on additional objects such as Entities, use the UniqueKeyWith(params object[]) method.
string UniqueKey { get; }
Property Value
Remarks
If you get a fresh IKeyService it will also create a new UniqueKey.
So your code should usually use the built-in property UniqueKey which comes from the shared ServiceKit Key.
Methods
AsEntity(ICanBeEntity)
Unwraps a dynamic entity or ITypedItem back into the underlying IEntity
IEntity AsEntity(ICanBeEntity thing)
Parameters
thingICanBeEntity
Returns
- IEntity
A normal IEntity
AsItem(object, NoParamOrder, bool?, bool?)
Convert something to a ITypedItem. This works for all kinds of IEntitys, IDynamicEntitys as well as Lists/Enumerables of those.
Will always return a single item. If a list is provided, it will return the first item in the list. If null was provided, it will return null.
ITypedItem? AsItem(object data, NoParamOrder noParamOrder = default, bool? propsRequired = null, bool? mock = null)
Parameters
dataobjectAn original object which can be converted to a TypedItem, such as a IEntity .
noParamOrderNoParamOrderpropsRequiredbool?make the resulting object strict, default
truemockbool?Specify that the data is fake/mock data, which should pretend to be an Item. Default is
false
Returns
Remarks
New in v16.02
AsItems(object, NoParamOrder, bool?)
Convert an object containing a list of Entities or similar to a list of ITypedItems.
IEnumerable<ITypedItem> AsItems(object list, NoParamOrder noParamOrder = default, bool? propsRequired = null)
Parameters
listobjectThe original list which is usually a list of IEntity objects.
noParamOrderNoParamOrderpropsRequiredbool?make the resulting object strict, default
true
Returns
Remarks
New in v16.01
AsList<T>(object, NoParamOrder, bool)
Convert a list of Entities or TypedItems into a strongly typed list.
Typically, the type will be from your AppCode.Data.
IEnumerable<T> AsList<T>(object source, NoParamOrder protector = default, bool nullIfNull = false) where T : class, ICanWrapData
Parameters
sourceobjectthe source object - a List/Enumerable of
IEntityorITypedItemprotectorNoParamOrdernullIfNullboolif
truewill return null whensourceisnull- otherwise a wrapper item with empty-contents
Returns
- IEnumerable<T>
Type Parameters
Tthe target type
Remarks
Release in v17.05
AsStack(params object[])
Create a typed object which will provide all the properties of the things wrapped inside it. The priority is first-object first, so if multiple items have the property, the first in the list will be returned.
ITypedStack AsStack(params object[] items)
Parameters
itemsobject[]objects to stack together
Returns
AsStack<T>(params object[])
Create a custom-typed object which will provide all the properties of the things wrapped inside it. The priority is first-object first, so if multiple items have the property, the first in the list will be returned.
T AsStack<T>(params object[] items) where T : class, ICanWrapData, new()
Parameters
itemsobject[]objects to stack together
Returns
- T
Item of the custom type
Type Parameters
T
Remarks
New in 17.07
AsTyped(object, NoParamOrder, bool?)
Creates a typed object to read the original passed into this function. This is usually used to process objects which the compiler can't know, such as anonymous objects returned from helper code etc.
If you have an array of such objects, use AsTypedList(object, NoParamOrder, bool?).
ITyped AsTyped(object data, NoParamOrder noParamOrder = default, bool? propsRequired = null)
Parameters
dataobjectnoParamOrderNoParamOrderpropsRequiredbool?make the resulting object strict, default
true
Returns
AsTypedList(object, NoParamOrder, bool?)
Create a list
IEnumerable<ITyped> AsTypedList(object list, NoParamOrder noParamOrder = default, bool? propsRequired = null)
Parameters
listobjectList/Enumerable object containing a bunch of items to make typed
noParamOrderNoParamOrderpropsRequiredbool?make the resulting object strict, default
true
Returns
As<T>(object, NoParamOrder, bool)
Convert an Entity or TypedItem into a strongly typed object.
Typically, the type will be from your AppCode.Data.
T As<T>(object source, NoParamOrder protector = default, bool mock = false) where T : class, ICanWrapData
Parameters
sourceobjectthe source object - an
IEntityorITypedItemprotectorNoParamOrdermockboolif
truewill return a fake whensourceisnull- otherwise a wrapper item with empty-contents
Returns
- T
Type Parameters
Tthe target type
Remarks
Released v17.05