Results 1 to 5 of 5

Thread: ASP.Net trying to understand 3-tier with auto-mapping and dependency injection

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011

    Lightbulb ASP.Net trying to understand 3-tier with auto-mapping and dependency injection


    I am from a hobbyist background using Windows Forms and am learning ASP.Net MVC. I am currently trying my hand at understanding the n-tier architecure, specifically trying to implement a 3-tier solution with the following projects that so far contain the listed items (they have been pieced together from my interpretation of various tutorials that each provided pieces of the puzzle, but not the whole puzzle):

    +++ [Project.Application] ++++

    => Project.Data
    => AutoMapper

    [Config Folder]
    => AutoMapperConfig.cs (Profiles for Project.Application.DTOs and Project.Data.Models)

    [DTOs Folder]
    => DTO Models

    [Services Folder]
    => Service Classes
    +=> [Interfaces Folder]
    +=> Service Interfaces

    +++++++ [Project.Data] +++++++

    [Config Folder]
    => App.Config (Storing database connection)

    [Models Folder]
    => Model Classes

    [Repositories Folder]
    => BaseRepository Class (Implements the IConnectionProvider)
    => Repository Classes (Inherits from BaseRepository)
    +=> [Interfaces Folder]
    +=> Repository Interfaces

    [Root Folder]
    => IConnectionProvider Interface
    => ConnectionProvider Class (Sets up the database connection using the App.Config connection string)

    ++++++++ [Project.UI] ++++++++

    => AutoMapper
    => AutoFac
    => AutoFac.Integration.MVC
    => Project.Application
    => Project.Data

    [App_Start Folder]
    => ContainerConfig.cs (Setup the AutoFac DependencyInjection container and registers MVC Controllers/Services/Repos and AutoFac profiles)
    => MapperConfig.cs (Configures the AutoFac mapping profiles found in Project.Application)


    At this point I have some questions:

    1. Am I going along the right path? My initial understanding is that my Appliation project should be acting as a go between for the UI and Data projects, however the addition of model mapping and dependency injection require me to add project references to the UI layer (for the sake of configuration) meaning I can no longer reference the projects in that way.

    2. I am now at the point of setting up a Controller in the UI project and think I should create my ViewModels here as well. That pushes me towards configuring mappings between the UI ViewModels and the Application DTOs which are already themselves mapped to the models in the Data project. It just feels wrong to map data twice between the UI and Data projects.

    3. Do you know of a good resource, or example project, bearing in mind I know this gets tricky with the addition of AutoMapper and AutoFac for model mapping and dependency injection (i've searched around alot already).

    Whilst there are probably better implementations than a 3-tier solution with the configuration I am using, I am hoping to achieve this moreso for my own understanding before then exploring other avenues.

    Thanks for any help
    Last edited by jay20aiii; Sep 7th, 2019 at 03:16 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width