José F. Romaniello

Las aventuras y desventuras de un codificador.

As you can note in my previous posts I’ve talked a lot about NHibernate and WPF. So I've decided to write an ongoing series of blog posts about the integration of these two technologies.


The motivation behind this series of posts is very simple most of the articles that you can read about NHibernate are for web technologies such as ASP.Net or ASP.NET MVC. Despite the fact that NHibernate is an ORM and has nothing to do with the presentation layer there are certain consideration that you have to take into account to build a good architecture.

Sample Domain

For this series of post I have chosen to use a small subset of the Chinook database with few modifications. I have changed all the Identities primary keys to HiLo. You can find both the original and the slightly modified version here (with class, mappings and read only tests).

This is the full database schema:

However we will focus in this subset of the domain:



A word about session management

Most of the examples of NHibernate for web applications uses a pattern called “Session-per-Request”, this means that the session and the transaction has the same lifetime that the web request. This pattern is very easy to work with and very easy to understood but is not suitable for desktop applications.
There are two antipatterns called “session-per-application” and “session-per-call” that you need to avoid.
The pattern that I will use for this series is called “conversation per bussines transactions” and is very well described by his inventor Fabio Maulo. I’ve learned a lot with Fabio and Gustavo Ringel  about CpBT.

A word about data binding

In this series of post we will make intensive use of WPF data binding capabilities. Is for that reason that I’ve written uNHAddIns.WPF that uses NHibernate extensions points to bring us few behaviors that we need for data binding.

The interface that we have to solve


The user need this very complex GUI. The user-story is as follows:

  • The user can have multiple instances of this window open for editing albums of different artists.
  • The user can add albums.
  • The user can add tracks to the new albums and preexistent albums.
  • None of the information is persisted until the user press “Save All”.
  • If the user press close the application will ask to the user if he really want to discard all changes.

This is all for now, in the next post I will talk about the architecture that I will use.

| More

6 comentarios:

Hi,José F

I read you The ChinookMediaManager example, I have a question for it.

I want to add a custom NH even in ChinookMediaManager,be used for at
delete object validate has relationship ,If has then not allow delete
it ,It not then delete it

Can I Help you ? In ChinookMediaManager attach this function for



Sorry, but an event isn't the correct place for doing such validation.
Take a look to the cascade attribute in the mapping.

Jose, te felicito por tus aventuras y desventuras, son las cosas que hacen crecer a una persona.
Estoy viendo si utilizo uNHAddins para un proyecto proximo y me encantaron tus articulos.
Este proyecto lo estoy planteando con Prism para WPF y Silverlight, sobre nHibernate; la aplicacion requiere que sea tanto WPF como Silverlight, por lo que estuve viendo Prism me viene de 10.
Ahora que veo esto de uNHAddins,  lo quiero estudiar para poder utilizarlo pero.............. que pasa con Silverlight? estuve buscando algo de info sobre uNHAddins en silverlight y no encontre nada, lo soporta??
Te agradeceria si me podes comentar al respecto.

José F. Romaniello dijo...

@Alejandro: Silverlight es una historia totalmente diferente por que implica separación física de capas. En mi ejemplo de Chinook Media Manager, existe una separación lógica muy fuerte de capas, pero no esta preparada esa arquitectura para separarse físicamente. Esto quiere decir, que con este ejemplo no serías capaz de poner las capas de negocio en un servidor, y la presentación en otro. Mi idea de este ejemplos es algo que se ejecuta todo en la misma maquina.
Dicho esto paso a explicarte que silverlight es una historia totalmente diferente por que tenes que usar si o si webservices en el medio. Y ahí ya no se puede utilizar CpBT sino que tenes que usar algo como Session-per-Request en los webservices, lo mismo que se hace para una aplicación web.

Estoy muy agradecido por tu pronta respuesta.
No lo podre usar para el proyecto que estoy planificando, pero si lo usare para otros en mente.
Muchas Gracias Jose

José F. Romaniello dijo...

Alejandro, la arquitectura del ejemplo no es un todo o nada, hay muchas
cosas que se pueden usar, mas alla del tema WPF y NHibernate lo bueno de la
arquitectura es que esta todo desacoplado y se puede reemplazar facilmente
muchas partes.Te cmoento que esta arquitectura la he estado presentando en
reuniones virtuals de Altnet conjuntamente con Fabio Maulo, podes ver los
videos aqu�:

Publicar un comentario