开发者

Pros and Cons of Fluent and XML Configuration

If you w开发者_运维知识库e'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

  • Strongly typed evaluated by compiler
  • Conditional configuration

Cons

  • Unabled reconfigured after build

XML Configuration

Pros

  • Ability to easily change after deploy

Cons

  • XML is verbose
  • More vulnerable to typing mistake


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.


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:

  • readability
  • self documenting tags (of course if you create those ;) )

Cons:

  • file length, but I wouldn't bother that

Currently all my projects are XML based.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜