This project has moved and is read-only. For the latest updates, please go here.


Configuration files you can use with an AppCan app.

A ContextDef/Region definition file often call ContextsDefs.xml.

This file allows defining of ContextDef's, the types within them and regions.

 That file can reference a somewhat standard unity configuration file like unity.config.


The contextdefs section

This contains one or more contextdef elements. 


unitconfigfile - This property can be set to the name of a file for using the full unity configuration options.  In the config file, Unity section names should match contextdef names to have them registered to the context.


Contextdef element


name - This is the name of the context that contained elements should be registered into.

 createop - This can be  ViewFirst, ViewModelFirst or  None.  This indicates which class should be created first when a context is created, this allows for View first or ViewModel first functionality.




Contains an optional registertypes element that itself will contain registertype.

Contains an optional regions element that itself will contain region elements.


registertypes element

Cotains registertype elements.


registertype element

Contained in a register types element.


alias - The type that must be used to resolve for the unity container (optional)

type - The underlying type that will be instatiated (required)


regions element

Contains region elements


region element

These are used to register types with a region (and if needed a context to resolve them from).


name - Name of the region

type - type to resolve for this region

context - (optional) the context to use to resolve the type from.




Example configuration file from HelloWorld sample Contexts.xml:

<?xml version="1.0" encoding="utf-8" ?>

<contextdefs unityconfigfile="unity.config">
  <contextdef name="HelloWorld.Shell">
      <region name="MainRegion" type="AppCan.wpf.Views.IView,AppCan.wpf" context="HelloWorld.Region.MainRegion"/>

      <registertype alias="AppCan.wpf.Views.IViewContainer,AppCan.Wpf" type="HelloWorld.Shell, HelloWorld" />
      <registertype alias="AppCan.wpf.Views.IViewModel,AppCan.wpf" type="HelloWorld.ShellViewModel, HelloWorld" />

  <contextdef name="HelloWorld.Region.MainRegion">
      <registertype alias="AppCan.wpf.Views.IView,AppCan.Wpf" type="HelloWorldModule.Views.HelloWorldView, HelloWorldModule" />
      <registertype alias="AppCan.wpf.Views.IViewModel,AppCan.wpf" type="HelloWorldModule.Views.HelloWorldViewModel, HelloWorldModule" />
Example of a somewhat standard unity.config file that is referred to by Contexts.xml file.
This can be used to take advantage of the full power of the unity configurations.  The only
difference is you should name the configSections, section name= to the name of the ContextDef
you want the types to be registered with.  The Contexts.xml file refers to this file in its
<contextdefs unityconfigfile="unity.config"> unityconfigfile property is the name of the file to
use (optional).
<?xml version="1.0" encoding="utf-8" ?> 

  <section name="HelloWorld.Shell"
                 Microsoft.Practices.Unity.Configuration" />



    <!-- Lifetime manager types -->
    <typeAlias alias="singleton"
               Microsoft.Practices.Unity" />
    <typeAlias alias="external"
               Microsoft.Practices.Unity" />

    <!-- User-defined type aliases -->
    <typeAlias alias="IMyInterface"
         type="MyApplication.MyTypes.MyInterface, MyApplication.MyTypes" />
    <typeAlias alias="MyRealObject" 
         type="MyApplication.MyTypes.MyRealObject, MyApplication.MyTypes" />
    <typeAlias alias="IMyService"
         type="MyApplication.MyTypes.MyService, MyApplication.MyTypes" />
    <typeAlias alias="MyDataService"
         type="MyApplication.MyTypes.MyDataService, MyApplication.MyTypes" />
    <typeAlias alias="MyCustomLifetime" 
         type="MyApplication.MyLifetimeManager, MyApplication.MyTypes" />











Last edited Mar 17, 2013 at 9:36 PM by davesspacebar, version 10


No comments yet.