1

I'm writing a C# application, I want to follow a 3-tier programming architecture. I've been programming my application based on this article.

I have some questions that I hope someone can help me with:

  • Where do i put the domain objects (for instance a Person class, where i put the getters and setters and the constructor, and all its properties (age, name,..). Do i put these in the BLL folder or someowhere else?

  • Should I put all my BLL functions that call functions from my DAL-layer in one controller or seperated among all specific business classes (for instance person, order,..)?

  • Do I need to create a DAL-object in every BLL function before calling a DAL-function, or do I use a singleton pattern where I only create one DAL-class object at a time?

A screenshot of my classes (Program.cs is the main class):

class structure

  • As with most things, it depends. For example, as the application grows in size your `Person` object will start to look a lot different in each of the layers. There could be a `PersonViewModel` in the View that holds the data as it is needed for display, the `Person` entity in BL as it is need for manipulation according to business logic and perhaps a `PersonDTO` to represent the same data as is most useful for persistence. – David Culp Dec 26 '17 at 14:16
  • Start with a `Person` entity in the BL and keep in mind that it is for manipulation by business logic. When you come get the point the data needs manipulated for view or for persistence purposes, create separate objects specific for those purposes and map between them in a way that makes sense to your application. – David Culp Dec 26 '17 at 14:19

2 Answers2

0
  1. I would say the domain objects would go inside DAL folder as the these object will be storing the data inside the instance of an object.
  2. I wouldn't suggest to place all BLL functions under one controller. One of the reason for 3 tier architecture even for a "single machine, single project" is to have code segregation so that it would be easy to understand and maintain.
  3. Singleton pattern means the same object would be shared with all BLL functions. If your main aim of the DAL is have one single storage interaction (e.g. Database) then having multiple DAL objects would mean multiple Database connections which means resource utilization concern. Even in case off multi threaded situations you can increase the Database Connection pool size to a constant number and make sure you share the pool with threads. Important of this that you do not request unnecessary resources from Database.
harshal
  • 592
  • 6
  • 25
0

There various solutions are possible, but e.g. Core platform shows that "more abstractions to the God of abstraction" is a trend. I guess because they find it is more easy to manage it this way in theirs development process (cross-platform, open source).

So do it with maximum possible abstraction and check how it is comfortable for you.

I have entities, service interfaces in one assembly. "Business" code I store in the entity (may be in instance method, maybe in static method, may be in static extension - there are no big difference between them). POCO doesn't mean "can't contain method".

Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142