How to pass a list of dependencies as a parameter

May 11, 2009 at 2:54 PM

Hello,

I have a Logger  which accepts Appenders, and I would like to configure which appenders to use.

My logger has an AddAppender method, and I defined Method Injections as follows:

              <method name="AddAppender">
                <param name="Appender" parameterType="IAppender">
                  <dependency name="ConsoleAppender" />
                </param>
              </method>
              <method name="AddAppender">
                <param name="Appender" parameterType="IAppender">
                  <dependency name="FileAppender" />
                </param>
              </method>

But it looks like only the last appender will be injected (silently ignoring the first declaration).

I have control over the Logger class, but I need to declare the appenders via configuration. Is there a way to configure a list of dependencies ?

Thanks for your help.

 

May 12, 2009 at 4:05 AM
Edited May 12, 2009 at 5:39 AM

There is actually an example in the documentation:

<constructor>
     <param name="loggers" parameterType="ILoggerArray">
            <array>
                <dependency name="logger2"/>
                <dependency name="logger1"/>
           </array>
     </param>
</constructor>

 

You can do the same for method injection

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

 

 

May 12, 2009 at 3:18 PM

That works, thanks.

I guess it's not possible to use multiple method injections with the same method.

Thanks for your help!