Share via


The Assembly Matching Rule

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.

The Assembly Matching Rule allows developers, operators, and administrators to select target classes based on the assembly name.

Behavior of the Assembly Matching Rule

In more detail, the Assembly Matching Rule does the following:

  • It reads the value of the constructor parameter to configure the matching rule for injection. For the assemblyName parameter, the value can be the assembly name; the name and version; the name, version and culture; or the fully qualified assembly name and details.
  • It compares the assemblyName value to the name and version; the name, version and culture; or the fully qualified assembly name and details of the target assembly excluding the .dll file name extension.
  • It returns True if the assemblyName string exactly matches the assembly details; if the match string does not exactly match the assembly details, it returns False.

Configuration Using Constructor Injection for the Assembly Matching Rule

Unity uses constructor injection to generate new instances of matching rules. For information about constructor injection, see the following topics:

The following constructor overloads can be used for the AssemblyMatchingRule class.

public AssemblyMatchingRule(
Assembly assembly
)
public AssemblyMatchingRule(
string assemblyName
)

The constructor parameters make the following configuration settings available for the Assembly Matching Rule:

  • assembly (Assembly). This represents an assembly object. This is the assembly to match.
  • assemblyName (String). This is the assembly name to match. This can be the name and version; the name, version and culture; or the full assembly name of the assembly excluding the .dll file name extension. It cannot include wildcard characters. The following are some examples:
    • "Contoso.BusinessObjects.Sales"
    • "Contoso.BusinessObjects.Sales, Contoso.BusinessObjects"
    • "Contoso.BusinessObjects.Sales, Contoso.BusinessObjects, Version=1.0.0.0"
    • "Contoso.BusinessObjects.Sales, Contoso.BusinessObjects, Version=1.0.0.0, Culture=neutral"
    • "Contoso.BusinessObjects.Sales, Contoso.BusinessObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"