Discovery, sometimes called probing, is the process DevForce uses to find your entity models and custom components.
DevForce uses the Managed Extensibility Framework (MEF) from Microsoft to provide much of its runtime extensibility. When your application starts, DevForce builds a "parts" catalog on both client and server containing the customizations it has discovered. By default, DevForce will check all non-system / non-IdeaBlade assemblies for "exports", i.e.,implementations of the DevForce interfaces and base types, as well as other components or your application.
The CompositionHost manages the discovery process, and provides properties and methods you can use to modify the default behavior, access the underlying MEF container, and add dynamic content.
In a large application with many assemblies you may find that the discovery performed at startup takes too long, or maybe you decide there's just no reason to look in assemblies which will never contain exports or entity models. Trace messages about the assemblies added the the "parts" catalog, all probe assemblies found, and total discovery time are written to the debug log and can help diagnose a problem.
The easiest and most common way to alter the default discovery behavior is to change the search and/or ignore pattern(s) DevForce will use.
For ASP.NET and Silverlight applications the default SearchPattern is "*.dll"; for other applications the default is "*.dll" and "*.exe".
For all application types, the default IgnorePatterns are set to exclude IdeaBlade and system assemblies, as well as assemblies from many third party control suites.
Both SearchPatterns and IgnorePatterns accept either simple wildcards or Regex patterns. Simple wildcard searches are converted into Regex patterns by DevForce when probing occurs. The search is case insensitive.
When should you use SearchPatterns versus IgnorePatterns? SearchPatterns are useful when you know specifically what you're looking for; while IgnorePatterns are helpful when you know what you don't want.
Here's a sample using the SearchPatterns to limit probing to only a single assembly. Generally in larger applications you'll have multiple assemblies to be probed, so you should be sure to include one or more patterns to cover them. This first clears the default SearchPatterns, and then sets a pattern for a specific assembly named "MyDomainModel.dll".
C# | IdeaBlade.Core.Composition.CompositionHost.SearchPatterns.Clear(); IdeaBlade.Core.Composition.CompositionHost.SearchPatterns.Add("MyDomainModel.dll"); |
VB | IdeaBlade.Core.Composition.CompositionHost.SearchPatterns.Clear() IdeaBlade.Core.Composition.CompositionHost.SearchPatterns.Add("MyDomainModel.dll") |
Now let's try modifying the IgnorePatterns. DevForce will by default ignore IdeaBlade and system assemblies, as well as a number of third party assemblies. You shouldn't clear this list, and you certainly shouldn't remove the "IdeaBlade.*" assemblies, since both actions will cause your application to fail, but you can add additional third party tools and suites to the list. For example, here we're adding an exclusion for all assemblies (and other files) matching "GalaSoft.*".
C# | IdeaBlade.Core.Composition.CompositionHost.IgnorePatterns.Add("GalaSoft.*"); |
VB | IdeaBlade.Core.Composition.CompositionHost.IgnorePatterns.Add("GalaSoft.*") |
You need to set the SearchPatterns and IgnorePatterns as early as possible in your application, since as soon as you use the IdeaBladeConfig.Instance, TraceFns and DebugFns methods, or an EntityManager, initialization will automatically occur.
If you've set SearchPatterns and/or IgnorePatterns, it's usually a good idea to check the debug log for the tracing messages written about what DevForce has discovered. It's easy to mistype a pattern and not have your assemblies probed, or alternately to have too many assemblies probed resulting in poor startup performance.
The first time DevForce finds and uses your custom classes it will log this fact to the debug log (or other ITraceLogger implementation). This information, along with logging about all assemblies loaded into the "parts" catalog, can help in diagnosing problems should they occur.
There are several components of your application which DevForce must find in order for your application to work as wanted.
In all the above cases, DevForce will look through all the assemblies which have been probed to find what it needs. If you've chosen to modify either the SearchPatterns or IgnorePatterns, make sure that the patterns will allow all assemblies needed to be discovered. You can check the read only CompositionHost.Instance.ProbeAssemblies at runtime to see which assemblies were found; they're also listed in the debug log.