title: Business Layer structure, how do you build yours?
body: <p>I am a big fan of NTiers for my development choices, of course it doesnt fit every scenario.</p>
  
  <p>I am currently working on a new project and I am trying to have a play with the way I normally work, and trying to see if I can clean it up. As I have been a very bad boy and have been putting too much code in the presentation layer.</p>
  
  <p>My normal business layer structure is this (basic view of it):</p>
  
  <ul>
  <li>Business
  
  <ul>
  <li>Services
  
  <ul>
  <li>FooComponent
  
  <ul>
  <li>FooHelpers</li>
  <li>FooWorkflows  </li>
  </ul></li>
  <li>BahComponent
  
  <ul>
  <li>BahHelpers</li>
  <li>BahWorkflows  </li>
  </ul></li>
  </ul></li>
  <li>Utilities
  
  <ul>
  <li>Common</li>
  <li>ExceptionHandlers</li>
  <li>Importers</li>
  <li>etc...</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Now with the above I have great access to directly save a Foo object and a Bah object, via their respective helpers.</p>
  
  <p>The XXXHelpers give me access to Save, Edit and Load the respective objects, but where do I put the logic to save objects with child objects.</p>
  
  <p>For example:</p>
  
  <p>We have the below objects (not very good objects I know)</p>
  
  <ul>
  <li>Employee</li>
  <li>EmployeeDetails</li>
  <li>EmployeeMembership</li>
  <li>EmployeeProfile</li>
  </ul>
  
  <p>Currently I would build these all up in the presentation layer and then pass them to their Helpers, I feel this is wrong, I think the data should be passed to a single point above presentation in the business layer some place and sorted out there.</p>
  
  <p>But I'm at a bit of a loss as to where I would put this logic and what to call the sector, would it go under Utilities as EmployeeManager or something like this?</p>
  
  <p>What would you do? and I know this is all preference.</p>
  
  <h1>A more detailed layout</h1>
  
  <p>The workflows contain all the calls directly to the DataRepository for example:</p>
  
  <pre><code>public ObjectNameGetById(Guid id)
  {
      return DataRepository.ObjectNameProvider.GetById(id);
  }
  </code></pre>
  
  <p>And then the helpers provider access to the workflows:</p>
  
  <pre><code>public ObjectName GetById(Guid id)
  {
      return loadWorkflow.GetById(id);
  }
  </code></pre>
  
  <p>This is to cut down on duplicate code, as you can have one call in the workflow to getBySomeProperty
  and then several calls in the Helper which could do other operations and return the data in different ways, a bad example would be public GetByIdAsc and GetByIdDesc</p>
  
  <p>By seperating the calls to the Data Model by using the DataRepository, it means that it would be possible to swap out the model for another instance (that was the thinking) but ProviderHelper has not been broken down so it is not interchangable, as it is hardcode to EF unfortunately.
  I dont intend to change the access technology, but in the future there might be something better or just something that all the cool kids are now using that I might want to implement instead.</p>
  
  <h1>projectName.Core</h1>
  
  <pre><code>projectName.Business
      - Interfaces
          - IDeleteWorkflows.cs
          - ILoadWorkflows.cs
          - ISaveWorkflows.cs
          - IServiceHelper.cs
          - IServiceViewHelper.cs
      - Services
          - ObjectNameComponent
              - Helpers
                  - ObjectNameHelper.cs
              - Workflows
                  - DeleteObjectNameWorkflow.cs
                  - LoadObjectNameWorkflow.cs
                  - SaveObjectNameWorkflow.cs
      - Utilities
          - Common
              - SettingsManager.cs
              - JavascriptManager.cs
              - XmlHelper.cs
              - others...
  
          - ExceptionHandlers
              - ExceptionManager.cs
              - ExceptionManagerFactory.cs
              - ExceptionNotifier.cs
  
  
  projectName.Data
      - Bases
          - ObjectNameProviderBase.cs
      - Helpers
          - ProviderHelper.cs
      - Interfaces
          - IProviderBase.cs
      - DataRepository.cs
  
  projectName.Data.Model
      - Database.edmx
  
  projectName.Entities (Entities that represent the DB tables are created by EF in .Data.Model, this is for others that I may need that are not related to the database)
      - Helpers
          - EnumHelper.cs
  </code></pre>
  
  <h1>projectName.Presenation</h1>
  
  <p>(depends what the call of the application is)</p>
  
  <pre><code>projectName.web
  projectName.mvc
  projectName.admin
  </code></pre>
  
  <h1>The test Projects</h1>
  
  <pre><code>projectName.Business.Tests
  projectName.Data.Test
  </code></pre>