Reputation: 6654
If you we're about to start a new project with some third party libraries (logging, orm, di, whatever), would you prefer to configure all this libraries via programming with fluent interfaces or with XML files?
Would you use a library that only supports one of these options (Fluent or XML)? Or do you prefer libraries that gives you the possibility to choose between a variety of configuration strategies.
For those who like code, take this as a hypothetical example (written in C#).
This is Fluent Configuration:
LogConfiguration.ConfigureStorage()
.ForDatabase("CommonDB")
.AsMsSqlDatabase()
.WithConnectionString("server=(local); database=Northwind; Integrated Security=true;")
.AsDefault();
This is XML Configuration:
<logging>
<database name="CommonDB" provider="MSSQL" connString="server=(local); database=Northwind; Integrated Security=true;" default="true" />
</logging>
Finally, what are the Pros and Cons of Fluent and XML Configuration?
Until now, we've come to this:
Fluent Configuration in Code
Pros
Cons
XML Configuration
Pros
Cons
Upvotes: 0
Views: 686
Reputation: 3344
I would say that XML configs may be less verbose and even simpler than Java configs.
Look on my comparison of the same config on XML and on Java DSL in Spring Integrations's wireTap
config
Also XML configs may be more familiar to less experienced programmers. So efforts for maintain such configs in the future may be less.
Upvotes: 0
Reputation: 1504
If I understood you correctly by fluent you mean in code? If so, then definitely I'd choose XML. If by fluent you meant pure text files, then still I'd choose XML. Pros:
Cons:
Currently all my projects are XML based.
Upvotes: 0
Reputation: 18961
I tend to use xml for attributes I might want to change post-build (such as connection strings, loggers)
I prefer strongly typed (compiled) fluent configuration in code for things such as NHibernate mappings that only change during development.
Upvotes: 1