The best practice for Enterprise Architecture - NHibernate
Domain Driven Design
Enterprise Notes
- Seperated Interface
- Also known as Dependency Inversion
- Technique for establishing a clean separation of concerns between application tiers.
- Often use for separating the Data Access Layer and the Domain Object.
- There are 2 ways to do this
- Same projects but separate by Folder named
- Domain and Data folder
- Cons
- Layers shared a bi-directional dependency with each others.
- Can't prevent the dependency on each entity
- Difficult to do a unit test since the data access layer will depend on the real database.
- If include the database, it will slow down the test speed.
- Separate assemblies
- Project.Core or Project.Domain and Project.Data
- Project.Core
- Contains the domain object
- Data Access Object (DAO) Interface
- Project.Data
- Contains concrete implementation of DAO Interface
- Cons
- DAO can be a mock object for easy unit test.
- Dependency Injection (DI) or Inversion of Control (IOC)
- By doing the Separated Interface, the Domain Layer only known the interface
- DI will help to manage the concrete class for Domain Layer
- There are multiple IoC framework available
- Castle Windsor
- Unity
- NInject
- Autofac
- Structuremap
- Spring.Net
- Principle - http://www.objectmentor.com/resources/articles/dip.pdf
- Design by Contract (DBC)
Defining the Domain Layer
- Separated the Interface and Implementation
- Design consideration for a unit test.
- Abstract Factory - http://www.dofactory.com/Patterns/PatternAbstract.aspx
- Mock Object - http://www.betgenius.com/mockobjects.pdf
- Collection Generic Examined
- Mapping to the database
- 2 ways
- HBM-XML files
- Attribute Mapping
- NHibernate support the stored procedure.
Defining the DAO Layer
- Able to retrieving the data from Stored Procs
- Handling the NHibernate Session
- DAO Explaination - http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
NHibernate Performance Tuning
Reference:
Web: