views:

14

answers:

1

I have a ASP.Net 4.0 web application for which I need to create typed configuration class. What I mean is as follows:

class SettingsClass
{
    int count;
    string name;
    decimal amount;
}

Should map to the configuration file as:

<MyAppSettings>
    <xmlSerializationSection type="...">
        <SettingsClass>
            <count>2<count>
            <name>Moiz</name>
            <decimal>10.66</decimal>
        </SettingsClass>
    </xmlSerializationSection>
</MyAppSettings>

The configuration file was identified in the web.config as follows by a configuration section (Read ColorSettings as MyAppSettings) Configuration section in web.config

This was straight forward in ASP.Net 2.0 and Enterprise library 1.0

I am trying to achieve the same thing in ASP.Net 4.0 and Enterprise Library 5.0. However, the Enterprise Library Console of 5.0 does not work the same way as the Enterprise Library Configuration tool of 1.0.

I wanted to know how I should be going about in .Net 4.0 and Ent Lib 5.0 to achieve this same requirement. Is there a better means by which configuration can be handled for typed class in .Net 4.0/ent lib 5.0?

+1  A: 

XML configuration changed radically (and not really for the better) in .NET 2.0. You're going to want to look at the System.Configuration namespace and the classes there. This is no longer an enterprise library question, but really one about the framework itself.

Chris Tavares
Chris, not sure if I have understood you correctly. But the class-config file one-to-one that I am referring to, was done when .Net 2.0 was just out and so was enterprise library 1.0. Are you saying that things have changed radically from .Net 2.0 to 4.0 and EntLib 1.0 to 5.0?
Moiz Tankiwala
Enterprise Library 1.0 was targetted at .NET 1.0 / 1.1, not 2.0. Entlib 2.0 targetted .NET 2.0. .NET 2.0 deprecated IConfigurationSectionHandler, which was the hook that made it so easy to write configuration sections. It's a lot harder in 2.0, but on the plus side it's less flexible. (Can you tell I've been fighting with System.Configuration lately?)
Chris Tavares