Share via


Constructing Application Block Objects Directly

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

There are times when the configuration information for your application scenario does not reside in a configuration source. For example, your system may dynamically create configuration information from data entered by a user. For these situations, you can directly construct application block objects, passing the required configuration information to the constructor.

The factory methods return a generic provider interface. When you construct an application block object, you must construct a specific provider implementation type using the appropriate constructor parameters and pass the required arguments to the constructor. The parameters themselves may have been created with a factory or by calling their constructors. The following code shows how to construct the Data Access Application Block SqlDatabase object.

SqlDatabase db = new SqlDatabase(@"server=(local)\SQLEXPRESS;database=EntLibQuickStarts;Integrated Security=true");
'Usage
Dim db As SqlDatabase = New SqlDatabase("server=(local)\SQLEXPRESS;database=EntLibQuickStarts;Integrated Security=true")

Note

The Enterprise Library factories include code to enable instrumentation. If you directly construct application block objects, instrumentation will not be enabled for those objects. However, in most cases, you can bind the appropriate instrumentation listeners to the application providers. For more information about listeners and providers, see Enabling Instrumentation.