Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:20:41+00:00 2026-06-15T21:20:41+00:00

Background I’m trying to create a simple application to really understand the whole stack

  • 0

Background

I’m trying to create a simple application to really understand the whole stack of DDD+TDD+etc. My goal is to dynamically inject the DAL repository classes at runtime. This keeps my
Domain and Application Services layers testable. I plan on using “poor man’s DI” to accomplish
this for now … so I would do this in a simple Console application near startup:


    // Poor man's DI, injecting DAL repository classes at runtime
    var productRepository = new SimpleOrder.Repository.ProductRespository();
    var customerRepository = new SimpleOrder.Repository.CustomerRepository();
    var orderRepository = new SimpleOrder.Repository.OrderRepository();

    // Constructor injection into this class in the Application Services layer,
    // SimpleOrder.ApplicationFacade
    OrderEntry oe = new OrderEntry(customerRepository, orderRepository, productRepository);

To accomplish this dependency injection, I’ve created three repository interfaces:

-- ICustomerRepository
-- IOrderRepository
-- IProductRespository

A typical implementation:


    namespace SimpleOrder.Domain.Interfaces
    {
        public interface ICustomerRepository
        {
            Customer GetCustomerById(int customerId);
            void SaveCustomer(Customer customer);
        }
    }

** Notice that SaveCustomer references the Customer model class defined in the domain layer. This is typical of the other repositories.

HOWEVER I’m not sure which project / layer they should be implemented in. I have 5 projects in a solution:

  1. SimpleOrder.ConsoleClient (presentation)
    — I want to inject the specific implementation of the domain from here as the application

  2. SimpleOrder.ApplicationFacade (application services)
    — chunky higher-level, coarser-grained methods orchestrating lower-level methods in the domain

  3. SimpleOrder.Contracts
    — DTO classes used for communication between presentation and application services

  4. SimpleOrder.Domain (domain / bll)
    — domain model classes Customer, Order, OrderItem, Product

  5. SimpleOrder.Repository (dal)
    — implements the repository interfaces

Here are my options as I see it:

Option 1: Define the repository interfaces in SimpleOrder.Contracts …

PRO: this is where I think they should belong because I created this to share contracts between various concerns / layers. ex., DTOs are defined here.

CON: however the method signatures in of each interface references Domain model classes.
This means that I would have to add a reference to the SimpleOrder.Domain, but when the
SimpleOrder.Contracts is referenced in another project, it will have to carry
SimpleOrder.Domain along for the ride. This doesn’t feel right.

Option 2: Same scenario as above, but I ALSO define interfaces for each Domain model
class in the SimpleOrder.Contracts so I can break the coupling of the repository interfaces to the actual model classes.

Example:


    namespace SimpleOrder.Domain.Interfaces
    {
        public interface ICustomerRepository
        {
            ICustomer** GetCustomerById(int customerId);
            void SaveCustomer(ICustomer customer);
        }

        public interface ICustomer
        {
            int CustomerId { get; set; }
            string Name { get; set; }
            System.Collections.Generic.List Orders { get; }
        }
    }

IMPACT: Each domain model class would have to implement his related interface. i.e.,


    public class Customer : SimpleOrder.Domain.Interfaces.ICustomer
    {
        public Customer()
        {
            _orders = new List();
        }

        public int CustomerId { get; set; }
        public string Name { get; set; }

        private List _orders;
        public virtual List Orders {
            get { return _orders; }
        }
    }

PRO: Fixes Option 1’s problem.

CON: This explodes the number of files (and the perceived complexity) in the project because
each domain class now has an associated interface.

Option 3: Define the repository intefaces in the SimpleOrder.Domain

IMPACT: In order to inject the concrete repository classes into the application services layer (SimpleOrder.ApplicationFacade project) from the SimpleOrder.ConsoleClient at runtime, SimpleOder.ConsoleClient will ALSO need a reference to SimpleOrder.Domain.

PRO: This ALSO solves Option 1

CON: I was trying to avoid referencing the domain layer from the presentation layer directly because now the presentation layer can know too much about the domain layer. When I replace the console application in the future with a WPF or ASP.NET MVC app in the future, I risk second and subsequent presentation layer implementations from attempting to call methods in the Model instead of the Application Services layer. (However I do consider this in Option 4.)

Option 4: Put the interfaces in SimpleOrder.Domain, then reference the SimpleOrder.Domain from the SimpleOrder.ConsoleClient.

PRO: Fixes all the problems above.

CON: This doesn’t feel right because I would be providing access from the presentation layer
directly to the lower-level methods in the Domain layer when I should only be providing
access to the higher-level chunky methods in the SimpleOrder.ApplicationFacade.

QUESTION
I’ve tried each of these, but have settled on Option 4, HOWEVER that leaves a bad taste in my mouth about it. Is there a better option? Am I on the right track here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:20:43+00:00Added an answer on June 15, 2026 at 9:20 pm

    From what I understand of your question, I would agree that option 4 is the best. The repository interfaces should be declared in the domain layer next to all of the domain objects. The implementation of said interfaces should be part of the infrastructure layer – the layer that connects your domain layer to the world. Take a look at the Hexagonal Architecture to see some of the motivation for this.

    To address the con of option 4, you shouldn’t think of the console app as being solely the presentation layer. It also has other responsibilities, such as being the host for the application and the composition root in DI terms. There could be a presentation component of the console app which only communicates with application services. You can also encapsulate the application service behind an open host service implemented with ASP.NET WebAPI. Then the presentation layer would only reference this service and be hidden from the underlying domain layer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I've inherited a web application that is intended to create on-the-fly connections between
Background Developing a simple web application (Eclipse + JBoss + Apache Tomcat) to generate
Background: We're building an application that allows our customers to supply data in a
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
Background I am working with a monad built of a stack of transformers one
Background The main application where I work is based heavily on the MUMPS-esque Caché
Background: I have an application with an alternate entry point. It listenes for SMS
Background info I am trying to upgrade a custom CMS to support the HTML5
Background: I've wrote a small library that is able to create asp.net controls from
Background to question: We are building an online web application that requires the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.