This project has moved. For the latest updates, please go here.

Configuration

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. 

Properties

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

Properties

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.

 

 

Elements

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.

Properties

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).

Properties

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">
    <regions>
      <region name="MainRegion" type="AppCan.wpf.Views.IView,AppCan.wpf" context="HelloWorld.Region.MainRegion"/>
    </regions>

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

  <contextdef name="HelloWorld.Region.MainRegion">
    <registertypes>
      
      <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" />
    </registertypes>
    
  </contextdef>
  
  
</contextdefs>
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" ?> 
<configuration>

<configSections>
  <section name="HelloWorld.Shell"
            type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
                 Microsoft.Practices.Unity.Configuration" />
</configSections>

<HelloWorld.Shell>

  <typeAliases>

    <!-- Lifetime manager types -->
    <typeAlias alias="singleton"
         type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager,
               Microsoft.Practices.Unity" />
    <typeAlias alias="external"
         type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager,
               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" />

  </typeAliases>

  <containers>

    <container>

      <types>

        

      </types>


    </container>


  </containers>

</HelloWorld.Shell>

</configuration>

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

Comments

No comments yet.