locked
How to separate domain classes from EF code first layer RRS feed

  • Question

  • User264732274 posted

    i am trying to get control over DDD with EF code first. i saw when people work with EF code first then domain classes reside there in same classes. just see a small example.

       public class TestDBContext : DbContext
        {
            public TestDBContext()
                : base("name=TestDBContext")
            {
            }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                //modelBuilder.Configurations.Add(new vwCustomerConfiguration());
                Database.SetInitializer<TestDBContext>(null);
            }
    
            public DbSet<Customer> Customer { get; set; }
            public DbSet<Addresses> Addresses { get; set; }
            public DbSet<Contacts> Contacts { get; set; }
            public virtual DbSet<vwCustomer> vwCustomers { get; set; }
            public DbSet<vwMyCustomers> vwMyCustomers { get; set; }
        }

    customer, address, contact and all domain classes are in same project but i want to put all these domain classes in different project.

    just see new project hierarchy which i am thinking to implement. all project name will start with my company then do and project name

    here it is

    1) Impex.Domain

    2) Impex.Storage

    3) Impex.Business

    4) Impex.UI

    so i will have 4 layers and those are domain, Storage, Business and UI. Storage, Business and UI these 3 layer will have reference of Domain layer because these 3 layers Storage, Business and UI may use domain classes.

    UI will pass data to business layer and received data from business layer. business layer again will talk to Storage layer where EF code first will be implemented to interact with DB.

    if i can successfully complete my project following 4 layers then people should consider my project is based on DDD pattern or not ?

    so tell me am i thinking right way. please give all your suggestion and guidance. thanks

    Tuesday, November 1, 2016 9:37 AM

Answers

  • User-821857111 posted

    if i can successfully complete my project following 4 layers then people should consider my project is based on DDD pattern or not ?
    Domain Driven Design doesn't specify any particular project structure. You cannot open a Visual Studio solution and determine from that whether an application was developed using a DDD approach.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 3, 2016 8:09 AM

All replies

  • User283571144 posted

    Hi sudip_inn,

    if i can successfully complete my project following 4 layers then people should consider my project is based on DDD pattern or not ?

    so tell me am i thinking right way. please give all your suggestion and guidance. thanks

    In my opinion, consider my project is based on DDD pattern is you have used this design model not just separate 4 project.

    As far as I know,  DDD has 4 layers:

    Storage:

    This layer provides technical framework support for other layers.

    Note that this section does not cover any business knowledge. Well-known data access content, has also been placed in the layer, because the data read and write is business-independent.

    Domain:

    Including the domain objects (entities, value objects) which involved in the business, domain services, and the relationships between them.

    This part of the specific form of expression is the domain model.

    Domain-driven design to promote the rich domain model, that is, as far as possible put the business logic to the domain object.

    Business:

    This layer does not contain any domain logic, but it will coordinate the task, and can maintain the status of the application.

    UI:

    This layer is show the data to the user.

    So I think you could firstly know more about DDD, then apply it to your project.

    More details about how to design domain dbcontext in EF with example, I suggest you could refer to follow link:

    https://msdn.microsoft.com/en-us/magazine/jj883952.aspx

    https://lostechies.com/jimmybogard/2014/04/29/domain-modeling-with-entity-framework-scorecard/

    Best Regards,

    Brando

    Wednesday, November 2, 2016 4:39 AM
  • User-821857111 posted

    if i can successfully complete my project following 4 layers then people should consider my project is based on DDD pattern or not ?
    Domain Driven Design doesn't specify any particular project structure. You cannot open a Visual Studio solution and determine from that whether an application was developed using a DDD approach.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 3, 2016 8:09 AM