Clarification needed on Loading UnityContainer from App.Config

Dec 19, 2008 at 5:11 AM
The unity section of my App.Config looks like this:
      <!--To replace, simply add two plugins for different datasource.-->
      <typeAlias alias="vmsDbPlugin" type="OCC600.VMSWebService.Plugin.WebServiceHelper, EMS.OCC600.VMSWebService.Plugin" />
      <typeAlias alias="vmsParser" type="OCC600.VMSWebService.Plugin.CriteriaParser, EMS.OCC600.VMSWebService.Plugin" />

      <!-- Agnostic types.-->
      <typeAlias alias="dataPlugInterface" type="OCC600.Infrastructure.Dictionary.Data.IDbAdapterHelper, EMS.Infrastructure.Dictionary" />
      <typeAlias alias="parserInterface" type="OCC600.Infrastructure.Dictionary.Data.Query.IExpressionTreeToCriteriaParser, EMS.Infrastructure.Dictionary" />
      <typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />      

          <type type="dataPlugInterface" mapTo="vmsDbPlugin" name="VmsDbPlugin"  >
            <lifetime type="singleton" />
          <type type="parserInterface" mapTo="vmsParser" name="vmsParser" />              

Upon application startup, I then make the following calls to load this configuration into an already created container as follows:

UnityConfigurationSection section  = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

Later, when I attempt to resolve type IDbAdapterHelper from the container, I get the following message:

{"The current build operation (build key Build Key[OCC600.Infrastructure.Dictionary.Data.IDbAdapterHelper, null]) failed: The current type, OCC600.Infrastructure.Dictionary.Data.IDbAdapterHelper, is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy, index 2)"}

Type mapping for this interface is defined but is not registering somewhere. What am I missing? 


Dec 19, 2008 at 8:10 AM
Did you pass the name of the type mapping when you call the Resolve method?


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc
Dec 19, 2008 at 3:55 PM
That's what I was missing, thanks.