People who are in .NET arena might encounter the plethora of xxx.config files especially web.config. It is a required devil for placing any configuration settings for your applications. We should appreciate the effort taken by the engineers at Microsoft for introducing (at that time, Java’s configuration approach is very immature) and providing a declarative approach, centralized and optimistic way of configuring your .NET application of any size. This has well fitted for applications written for simple purpose including training codes, in-house tools, etc. In a real-world, irrespective of small, medium or large scale, both Visual Studio and developers place lots of stuff on this mess sourrounded by <, >, />, ” characters.
When you see the web.config schema, it accomodates the following types of configuration for an application:
- Configuration section declaration (your custom configuration section)
- Startup settings
- Runtime settings such as impersonation, app domain manager, GC, CAS publisher policy, etc
- Remoting settings
- Network settings like authenticatio modules, proxy settings, System.Net, connection related
- Tracing and debug
- Application settings
- Connection strings
- ASP.NET settings like anonymous identification, authentication and authorization, caching, compiling, custom errors, health monitoring, HTTP runtime, handlers and modules, membership
- WCF settings like service endpoint, service behavior and binding configurations
Bit sleepy? Refer http://msdn.microsoft.com/en-us/library/ms731734.aspx for WCF and http://msdn.microsoft.com/en-us/library/dayb112d.aspx for ASP.NET specific settings.
There are machine wide settings those are overridden by site and application wide settings also. Does this really prouductive in development stage and helpful in production stage? Having experience on real world .NET applications, the main concerns with web.config are:
- Readability & Understandability. Though it has the capability of defining the whole earth even the whole universe, readability is very bad. Mentally, it outshines the content clarity.
Let us see a sample web.config for a WCF service. How easy for you to add some more settings related to WCF tracing?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
The above configuration is for a federated WCF web service.
When you refer the alternate representations of XML, you can feel the readability issue. Here is, an example JSON taken from Wikipedia:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
The same in XML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
The same in YAML which is very famous in Rails arena:
—
firstName: John
lastName: Smith
age: 25
address:
streetAddress: 21 2nd Street
city: New York
state: NY
postalCode: 10021
phoneNumbers:
– type: home
number: 212 555-1234
- type: fax
number: 646 555-4567
- Managability – the user who might be a developer, solution architect, production administrator have to manage lot of stuff to accomplish an intent. For example, WCF security related settings are scattered across service binding (security mode settings) and behavior (e.g. service credential settings) sections. Thought technically this is the correct way, however from an user perspective, this has lesser managability.
- Mixture Settings. since web.config is the only best place for any configuration, the “separation of concerns” principle couldn’t be achieved in various stages of configuration. For example, some settings are more helpful during development stage, for example, the list of claims types can be understood by a WCF service, assemblies for handling custom authentication, etc. But these configuration are no way helpful, but making this as configuration is harmful to the application at the production stage. Just think that changing “GivenName” claim to “GivenName2″ in the above sample web.config might break the system.
What is expected?
Yes, we should appreciate the level of flexibility and extensibility available in .NET. However, in the era of agile, productivity and simplicity are matters. It is time to adopt and follow “convention over configuration” approach those are main part in Rails and Android development world. If required, let the user (again developer or solution architect) override the convention.
Instead of putting everything on the messy XML tags, provide developer/solution architect/administrator friendly DSL, which would be internal DSL on C# or easy to learn external DSL. For example, in Rails, to map a web request to appropriate REST action is being configured by Ruby syntax.
1 2 3 4 5 6 |
|
In the above code, you see such mapping. These kind of scripting will be more favourable than the awkwardness XML.