Monday, December 22, 2008

Wiring up nHibernate with Web Service Software Factory

The backstory:

  • I'm in the (not?)unique situation where I need to start integrating multiple services and subsystems.

  • I write .NET code. I'm not a MS zealot. In fact, I'm an ALT.NET fan.

  • My boss, however, loves Java. A lot. He says "use JBoss ESB." I say "but, Biztalk? I know it!?" He says, "refer to previous statement."

Exit Criteria:

  1. Build some core data services. Purely persistance, no business rules.

  2. Expose them in an interoperable way (DataSets are the spawn of Satan)

  3. Add the minimal amount of code maintenance work. Note: this does not mean lines of code, this means amount of maintenance required.

Failed solution 1: Web Services Software Factory?

  • Use WSSF to create some nice looking schemas to expose to our service bus. Our database is less than optimal in its design, and i shouldn't be using the database as a model for my domain anyways.

  • WSSF is pretty nifty. Designers are great (they don't scale up well, though). Some nitpicks (tons and tons of code, all generateable, I know, but see Exit Criteria #3).

  • As great as the contracts are, I still have to write a ridiculous amount of data access code, or reuse the stuff I already have written (but don't really like)

Failed solution 2: Use nHibernate 2.0?

  • Get CodeSmith. Eric Smith is my hero.

  • Gen up a simple nHibernate layer on top of my database.

  • IList is not serializable. There are a lot of them in my entities. nHibernate objects look too much like my database. Yes, I got what I asked for. But it's not what i wanted ;-) Workarounds are possible, but even 1-to-1 object mappings are hard to get around because nHibernate loves its dynamic proxy generation (I do too. Just not now.)

  • Conceptually, I am right there with the ORM tool. However, it's pretty clear nHibernate is clearly not a good solution for my DTO needs.

Eureka! Use the tools to do what they are designed to do (duh.) WSSF helps me expose my service in a very agnostic (in comparison with other MS tools) way. nHibernate helps me avoid ever writing anything resembling a data adapter. CodeSmith helps me tie these things together.

so, it all looks like this (and works, BTW):



technical detail to follow after everyone is happy with it ;-)

No comments: