Export (0) Print
Expand All

Configuring Unity

One of the key tasks you need to perform when using Unity is to configure the container with the required aliases, type registrations, mappings, and other information that it requires in order to resolve objects at run time and inject the appropriate objects and values into dependent objects. This section covers all of the configuration options for Unity, and describes how you can configure the container using a configuration file, or at run time using code.

Unity can read configuration information from an XML configuration file. By default, this is the App.config or Web.config file for your application. However, you can load configuration information from any other XML format file or from other sources if required.

In addition, Unity exposes a series of methods that you use in your application code to configure the container. This approach is useful when the registrations and mappings depend on the environment or run-time information, and you can change the configuration at run time using these methods. Run-time configuration is also a good choice if you want to be able to manipulate container hierarchies at run time to change the overall behavior of type resolution, injection, and interception.

You can, of course, use a combination of design-time (configuration files) and run-time configuration to achieve exactly the configuration you require at any point during application execution.

To help you understand how to configure Unity, this section divides the information into two separate subsections—one for design-time configuration and one for run-time configuration. Each section contains basically the same set of topics that describe specific configuration scenarios.


Ff660846.note(en-us,PandP.20).gifNote:
The configuration files are not encrypted by default. A configuration file may contain sensitive information about connection strings, user IDs, passwords, database servers, and catalogs. You should protect this information against unauthorized read/write operations by using encryption techniques.
If you wish to restrict access to the configuration file, it must be encrypted or protected using Access Control Lists. It is recommended that the configuration store is in the same trust boundary and that decrypting the configuration is done in the same trust boundary after the configuration is read.


The complete set of topics in this section is as follows:

For information about using container hierarchies, see Using Container Hierarchies. For information about using Unity, see Using Unity in Applications.


Show:
© 2014 Microsoft