开发者

Advice on nhibernate project layout, want to put nhibernate related code in own project

开发者 https://www.devze.com 2023-04-03 21:14 出处:网络
I am building a asp.net mvc application, the projects I have in my solution so far is: Solution.PROJECT1

I am building a asp.net mvc application, the projects I have in my solution so far is:

Solution.PROJECT1
PROJECT1.Web
PROJECT1  
PROJECT1.Tests
PROJEC开发者_C百科T1.Data
PROJECT1.Data.Tests

So PROJECT1.Data has all my nhibernate related code: entities, mappings, and repositories.

PROJECT1 will have my service layer, and will reference the nhibernate project. Web will then only reference the service layer.

My question is, what if I have some objects that I need to put in both PROJECT1.Data and PROJECT1 ?

And example of that is a Logger class I wanted to created.

I want to avoid recursive assembly referencing etc.

Should I create another project with these classes?


Hi your design seems good, i would have a .Core class library project for logging and other common helpers, every project can reference it.

I would also have a separated .Interfaces and .Entities pair of projects, it happens often you want the UI to know an entity only by its interface so ui will not need to reference Entities but your servicelayer does.

I woul put the custom exception classes you could need in interfaces or common or entities. common is probably the best but it is lower than other two so it depends if you need one of those interfaces already.


In addition to what @Davide said:

I would consider extracting Entities to their own project, which will NOT reference Data or nHibernate.
That way you make sure that your domain model isn't dependent on the data representation.

Also I think it's advisable that the UI layer doesn't interact with the domain entities, but with DTOs (or presentation objects).
This wil further reduce the dependency between business logic and UI logic, and will also make it easier for you to send to the client only the things it needs (for example- the User entity may contain fields such as PasswordHash, Salt, LastUpdated. But you only want to display the user's name and last logon date. It's easier if you're using DTOs to create one that contains only what you need, and have your service layer return that.)

0

精彩评论

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