Extended ASP.net 2.0 resource provider Model (2)

Source: Internet
Author: User
Tags abstract naming convention

Database Resource Entries

It may be helpful to review the database table structure to store the actual resource entries first. The example contains a SQL script to create a database named Customresourceproviderssample and a table named Stringresources. Table 1 contains the following fields:

Table 1. database table with Resource entry

Field Description

ResourceType

The category of each resource. You can use it to differentiate between local resources for different pages, or to differentiate global resource types based on user-defined names.

Culturecode

The culture code in the supported CultureInfo code used by. NET is based on the ISO standard. You can also extend the code for any missing code.

ResourceKey

The resource key to use to retrieve the resource.

Resourcevalue

The resource value. This table supports strings up to 4 K.

In this example, all resources are stored in a separate table, although they can be distributed in several tables in order to optimize typical usage patterns in more complex or larger environments. The primary key for this table is a key combination, including ResourceType, Culturecode, and ResourceKey. A single resource value typically uses a primary key request. Figure 5 shows a partial view of the contents of the table.

Figure 5. Partial view of this sample resource entry

The ResourceType of a page resource is the name of the page, including its relative path in the application (that is, expressions.aspx,subdir1/expressions.aspx). This Convention distinguishes pages with the same name in different subdirectories, similar to the way the default resource provider model recognizes different local resource assemblies by subdirectories. The resource key for a control property follows the same naming convention as a typical page resource, using the control prefix and the property name, as follows.

[Prefix].[PropertyName]

Global resources have user-defined resourcetype. The sample code has several global resource categories: Glossary, Commonterms, and Config. The resource keys in this example are visually named for their contents.

The data access layer StringResourcesDALC the work to retrieve resources from the table based on the usage pattern of the provider model.

Extended ResourceProviderFactory

The ResourceProviderFactory type is the center of resource access in ASP.net 2.0, which is responsible for returning global or local resource providers based on the requested resource type. ResourceProviderFactory is an abstract base type that requires implementations of the following two methods: Createlocalresourceprovider () and Createglobalresourceprovider (). To create a custom provider factory, you need to inherit this base type to provide implementations of these methods. Both methods must return an instance of the resource provider that implements the IResourceProvider interface.

The basic resourceproviderfactory type declaration is shown in Listing 1.

Code Listing 1. ResourceProviderFactory abstract Type

public abstract class ResourceProviderFactory
{
 protected ResourceProviderFactory();
 public abstract IResourceProvider CreateGlobalResourceProvider(string classKey);
 public abstract IResourceProvider CreateLocalResourceProvider(string virtualPath);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.