How to register nested class in app.config

Jun 14, 2011 at 1:12 PM

Hi,

I have been searching for hours but didn't find a way how to register a nested class in the app.config file. The scenario is as follows: I need to create a class by means of a Factory-Class which is nested in the class it creates .

 

 
namespace ContainerTest
{
    public interface IFactory
    {
        SomeClass Create();
    }
    public class SomeClass
    {
        public class Factory : IFactory
        {
            public Factory()
            {
            }

            public SomeClass Create()
            {
                return new SomeClass();
            }
        }
        private SomeClass()
        {
        }
        public void DoSomeStuff()
        {
        }
    }
}

I am able to register this Factory class by writing

 

container.RegisterType<ContainerTest.IFactory, ContainerTest.SomeClass.Factory>();
However I need to register the class in the app.config.
Using <register type="ContainerTest.IFactory, ContainerTest" mapTo="ContainerTest.SomeClass.Factory, ContainerTest"/>
throws an exception during container configuration.

Is there any way to use the app.config file for this purpose?

Lisa


 

 
Jun 14, 2011 at 7:16 PM

Hi Lisa,

There is already a related issue logged for this see Issue #9284 for details. As workaround, you just need to register it in the config like the following

 <register type="ContainerTest.IFactory, SamplePost3" mapTo="ContainerTest.SomeClass+Factory, ContainerTest">

HTH

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 15, 2011 at 7:35 AM

Thank you!!!