Pages Html

NuGet packageOwin.Framework.Pages.Html
GitHub sourceOwinFramework.Pages.Html

Home |  Readme

[DataScope] attribute | The OWIN Framework Pages

The [DataScope] Attribute

You can attach this attribute to a Page element or a Region element to define the scope used to retrieve a specific type of data.

Example Usage

[DataScope(typeof(IAddress), "billing")]
public class BillingAddressRegion
[DataScope(typeof(IAddress), "delivery")]
public class DeliveryAddressRegion
[IsLayout("address-layout", "billing,delivery")]
[ZoneRegion("billing", "billing-address-region")]
[ZoneRegion("delivery", "delivery-address-region")]
[ZoneTemplate("billing", "/cart/invoice/address")]
[ZoneTemplate("delivery", "/cart/invoice/address")]
public class AddressLayout

Note that in this example the same address template is used in both zones of the address layout, and this template is data bound to the IAddress interface, but the zones will contain different addresses because of the [DataScope] attributes attached to the regions.

This is an important mechanism because it allows you to reuse the address template with different addresses even within the same layout.

The [DataScope()] attribute has the following properties you can set.


This property defines the type of data to scope. The data type can be any reference type or any IList<T> type.

This property is required and must be passed to the constructor.


Specifies the name of the scope that should be resolved below this point in the tree of elements on the page.

For example if I have a page element that binds to PersonViewModel with no scope name defined, this does not specify which person view model to bind to. In this case the framework will locate a Data Provider that is a provider of PersonViewModel data and ask it to supply a PersonViewModel with no scope name defined.

By adding a [DataScope()] attribute to the page, or a region within the page, we change this behavior. Lets assune we scope the PersonViewModel to logged-in-user scope. What happens now is that the framework looks for a Data Provider that advertises an ability to provide PersonViewModel in logged-in-user scope, and asks it to set a PersonViewModel into the data binding context in this scope.

This mechanism allows you to create one data bound template for the PersonViewModel type, and reuse this template in different contexts by setting the scope name on the container that contains the template.

By setting the data scope for different regions on the same page, the page can render PersonViewModel for different people on the same page using the same template.