开发者

nhibernate architecture

开发者 https://www.devze.com 2023-02-06 10:47 出处:网络
Hello I want to create my first nhibernate projet. It will be a migration from a winform project associated with an old dataacess with no strong orm mapping.

Hello I want to create my first nhibernate projet. It will be a migration from a winform project associated with an old dataacess with no strong orm mapping. The project is quite large so I'd like to have a good architecture from the beginning.

I will have some layer :

  • Repository : C开发者_开发问答reate the session from nhibernate
  • Model : The bean object, basically it consists of getter / setter properties with the same name in the database

But I'll need some advices, how will you handle the operations ? If I want to create an item should I access directly to nhibernate from the code ? Or should I create a business logic layer ?

Basically I found that simple architecture for the business layer. http://www.codeproject.com/KB/architecture/NHibernateArchitecture.aspx What is your feeling ?

Another question, it is a program with strong validation (glasses domain), where should be the validation ? in the winform project or in a business layer ?


It's hard to say and give useful advices without seeing the project and its actual problems. Is it client-server architecture for instance? What do you mean by "quite large"? There are too many different projects to have rules which fit all.

Generally:

  • In most of the cases, it is very useful to have a business layer.
  • validation should be in the business layer. There is also NHibernate validation and some other validation frameworks around, which allow declarative validation.

The most common mistake I see when starting with NH is that people don't understand persistence ignorance. This means that you should write your business logic without accessing the database or NH. Changes are made on the entities, they are not "temporarily" until they get explicitly applied to the database, they get implicitly stored when the transaction gets committed. This has a huge impact to the code. In many cases, there is no "Store" or "Update" or whatever.


Take a look at SharpArchitecture. It is a very good framework for NHibernate. Very good example on how to wire everything up.

http://www.sharparchitecture.net/

0

精彩评论

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

关注公众号