In my opinion you should have another Layer (seperate dll). Like "domain", where would you keep all entities like Customer. Then simply include in all higher levels(DAL, BLL, UI and others) in hierarchy this assembly Sample architecture can look like this: (Database) DAL BL UI and on all levels you will have access to "domain" layer.
DAL should return List not a DataTable. On some stage your development process you may want to use in DAL some OMR like Nbernate with would also return a List, probably.
In my opinion you should have another Layer (seperate dll). Like "domain", where would you keep all entities like Customer. Then simply include in all higher levels(DAL, BLL, UI and others) in hierarchy this assembly.
Sample architecture can look like this: (Database) DAL BL UI and on all levels you will have access to "domain" layer. DAL should return List not a DataTable. On some stage your development process you may want to use in DAL some OMR like Nbernate with would also return a List, probably.
I like this one. One question though - if I have Customer class in Model (or Domain, Entities) assembly, should this class also have all the methods, like GetAllCustomers, GetCustomer(int id),...? Or should the model have only properties and the methods should be in BLL? – pjotr Oct 17 '10 at 9:29 1 I would have the Customer class serve as a data entity only, so just properties and no methods like "GetAllCustomers".
That method I would put in the BLL that would use the DAL to make the query. – Ami Oct 17 '10 at 9:33 In this case I could add partial classes to BLL, which extend my base classes from Model assembly and add them methods? – pjotr Oct 17 '10 at 9:36 1 No, GetAllCustomers, GetCustomer(int id) should be placed in DAL (where you will get them from database, fill in to entities like Customer and return to BLL).
In 99% in BLL you will have a method like GetCustomer(int id) that will contain one line "return DAL. GetCustomer(id);" just to pass business data to UI. "domain" layer contains only business objects.
– klm_ Oct 17 '10 at 9:39 1 Yes, in most of the scenarios. Sometimes in Model assembly you can put also some validation. But logic like filtering customers or creating reports should be in DAL/BLL.In general, everything what manipulates data should be in BLL – klm_ Oct 17 '10 at 9:47.
I would use the following pattern as it allows you to upgrade to a different persistence strategy later. UI/Consumer BLL DAL/Persistence Here the View models are consumed outside the BLL and models are communicated across the BLL/DAL layers. In your case the model can be anything the DAL uses - DataTables for example or later perhaps ORM entities.
The BLL is responsible to mapping between the model and view model. As to keeping types in their own assemblies - yes for view models and in order to maintain a consistency, yes for the models as well. Keeping the models and view models separate stops leakage of the persistence strategies outside of the BLL and thus permits future design changes to the persistence.
One advantage of this separation is that that different view model consumers can have differing view models for the same persistence model/entity. Some could be small and have few attributes and others large and rich in functionality. It also permits you to introduce offline/disconnectedness capability as the view models could be returned at differing times allowing you decide data merging strategies.
This also allows you're persistence entities (e.g. Tables to grow and change shape). Since this looks like a . Net implementation things like AutoMapper will provide a lot of functionality out of the box Of course this may be way overkill for your app - however I'd still maintain a BLL mapping that only talks view models to all BLL consumers.
This should give you enough decoupling.
Pushing the domain entities into the dal is an option that would remove the crcular dependency, but may not match your intent. This isn't unheard of, though; for example LINQ-to-SQL gnerated entities would live in the DAL. Other options: put them into a common lower assembly (but that may leave your BL rather empty) use IOC to remove / reverse the reference between BL/DAL There are no single right answers here.Re DataTable; personally I agree - I'm not a fan ;) However, they can be used successfully and reasonably.
But if I had to use them, I'd be keeping them in the DAL as an implementation detail - and not exposing them above that.
It's hard to answer this general question without knowing the application domain well enough. I would start with thinking about where future changes are most likely and try to figure out from that where flexibility is required. My following thought are just a suggestion.
Feel free to consider them and change/ignore what you feel is irrelevant. Separating the DAL from the BLL is almost always a good idea. The data scheme is one thing that should be encapsulated and hidden from the rest of the application, so leave your DataTables, DataSets, ORMs or any other solution hidden in the DAL.
The BLL (and layers above it) should use simple data types (meaning simple classes). I think it would be a good idea to put those classes in a Model class library that has no references and can be used everywhere. It feels like you have a bit too much layering...do you really need a Customer class in the BLL and another one in the Application layer?
Could be, but I would make sure and think it twice over. From my experience in one of my recent project (a weather web site with 200K unique visitors daily), we used link2sql for data access (mostly read only data), and simple data classes all over our ASP. Net MVC application (of course as part of models/view models).
It worked quite smoothly, and we could easily change the data scheme without breaking down other layers. As for your last question about DataTables, these objects, should you decide to use them (I would vote against), belong solely in your DAL. They should not be exposed to other layers as that would create coupling to that specific class.
What if tomorrow MS invents a much better class? Would you switch over now that you have a gazillion references all over your projects to the DataTables, its method and properties? Would be nicer to just change your DAL to work with the NewAwsomeDataTable class and the rest of your app is blissfully ignorant.
Hope that helped :).
Re: ...do you really need a Customer class in the BLL and another one in the Application layer?... There is only one Customer class, wherever it is, sorry for misunderstanding :) That's why I wrote that Application uses BLL. Customer class and not just Customer class. – pjotr Oct 17 '10 at 8:53.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.