Hand-on Lab4 generic decorator chain task2 configuration File

Dec 2, 2009 at 1:32 PM

Hi there,

I'm quite new at this, and therefore started with the hands-on labs, which I find very good and well done.

However, for practice, I tried but couldn't manage to get rid of all the container configuration done in the program.cs class and place it in the config file, for the Resolving Generic Decorator Chains part (lab4, task 2).

I tried to directly "translate" (and then comment) the c# instructions into XML configuration:

                //TODO: add overrides here (as told to do so in lab4, task2, code given in the lab)
                //configure constructor for StocksTickerPresenter with the IRepository<StockQuote>
                container.RegisterType<StocksTickerPresenter>(new InjectionConstructor(typeof(IStocksTickerView),
                                                                                        typeof(MoneyCentralStockQuoteService), //<-- BTW, wouldn't it be IStockQuoteService instead? but this is not my point
                                                                                        new ResolvedParameter<IRepository<StockQuote>>("validating")));

                //mapping the opened generic IRepository<T> interface to the opened generic ValidatingRepository<T>
                //NOTE: Done with argument because of open generics
                container
                    .RegisterType(typeof(IRepository<>), typeof(ValidatingRepository<>), "validating")
                    .RegisterType<IValidator<StockQuote>, RandomStockQuoteValidator>();

which would give (respectively):

          <type type="StocksTickerPresenter">
            <typeConfig>
              <property name="Logger" propertyType="ILogger">
                <dependency name="UI"/>
              </property>
              
              <!--TEST:KO-->
              <!--<constructor>
                <param name="view" parameterType="IStocksTickerView"/>
                <param name="stockQuoteService" parameterType="IStockQuoteService"/>
                <param name="repository" parameterType="IRepositoryOfStockQuote" />
              </constructor>-->
            </typeConfig>
          </type>
          <type type="IRepository" mapTo="ValidatingRepository" name="validating"/>
          <type type="IValidatorOfStockQuote" mapTo="RandomValidatorOfStockQuote"/>

Seems OK for the last 2 types, but I can't manage to do it properly for the injection constructor configuration for the StocksTickerPresenter and can't get the app running... get a StackOverflow when launching before form appears...

What am I missing here?

Here are my aliases:

      <typeAlias
        alias="IRepository"
        type="PersistenceFramework.IRepository`1, PersistenceFramework" />
      <typeAlias
        alias="ValidatingRepository"
        type="PersistenceFramework.ValidatingRepository`1, PersistenceFramework" />

 

      <typeAlias
        alias="IRepositoryOfStockQuote"
        type="PersistenceFramework.IRepository`1[[StocksTicker.StockQuote, StocksTicker]], PersistenceFramework" />

      <typeAlias
        alias="IValidatorOfStockQuote"
        type="PersistenceFramework.IValidator`1[[StocksTicker.StockQuote, StocksTicker]], PersistenceFramework" />
      <typeAlias
        alias="RandomValidatorOfStockQuote"
        type="StocksTicker.RandomStockQuoteValidator, StocksTicker" />

thanks for your help

 

Dec 4, 2009 at 6:30 AM

I can't repro your error but here's the list of things that I've done on the StockSticker's app.config:

1. Added the following type aliases:

<typeAlias
        alias="ValidatingRepository"
        type="PersistenceFramework.ValidatingRepository`1[[StocksTicker.StockQuote, StocksTicker]], PersistenceFramework" />
<typeAlias
        alias="IValidatorOfStockQuote"
        type="PersistenceFramework.IValidator`1[[StocksTicker.StockQuote, StocksTicker]], PersistenceFramework" />
<typeAlias
        alias="RandomValidatorOfStockQuote"
        type="StocksTicker.RandomStockQuoteValidator, StocksTicker" />

2. Added the following type mappings:

<type type="IValidatorOfStockQuote" mapTo="RandomValidatorOfStockQuote"/>

 <type type="IRepositoryOfStockQuote" mapTo="ValidatingRepository" name="validating" >

3. Added the constructor injection config under the typeconfig element of the StocksTickerPresenter.

<type type="StocksTickerPresenter">
      <typeConfig>
              <property name="Logger" propertyType="ILogger">
                <dependency name="UI"/>
              </property>
              <constructor>
                <param name="view" parameterType="IStocksTickerView">
                  <dependency />
                </param>
                <param name="stockQuoteService" parameterType="IStockQuoteService">
                  <dependency />
                </param>
                <param name="repository" parameterType="IRepositoryOfStockQuote">
                  <dependency name="validating"/>
                </param>
              </constructor>
     </typeConfig>
</type>

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com