How should I handle my Entity/Domain Objects using IoC/Dependency Injection?

后端 未结 1 474
耶瑟儿~
耶瑟儿~ 2020-12-20 03:48

I\'m currently using PLINQO to generate all my Entities from the database.

Recently, I\'ve started to use dependency injection using StructureMap, and as part of the

相关标签:
1条回答
  • 2020-12-20 04:14

    I think you are on the right track - don't let the name of the generated L2S classes fool you. They are not Entities in the DDD terminology, but simply strongly typed representations of the database. If you ask me, that is an implementation detail that should not be allowed to invade the Domain Layer.

    With the currect .NET framework, and if you stay purely with the BCL and use no extra libraries, your only option is to define persistent-ignorant Entities in your Domain Model and then map those to the L2S classes in the data access layer. It's a pain, but AutoMapper can be helpful in that regard.

    If you are willing to deviate a bit from the pure BCL there are open-source libraries that offer persistence ignorance, such as NHibernate - I don't have any personal experience with NHibernate, but lots of smart people think highly of it.

    In .NET 4.0, the Entity Framework, and thereby LINQ to Entities will also offer persistence ignorance.

    Jeremy Miller has an article in MSDN Magazine that somewhat touches upon the subject.

    0 讨论(0)
提交回复
热议问题