开发者

IOC with Entity Framework

开发者 https://www.devze.com 2023-02-16 13:56 出处:网络
I am trying to make use of Unity Framework with Entity Framework. Let me explain the scenario. Let\'s say I have a Database with 5 tables. I will have 5 interfaces each of them corresponding to one ta

I am trying to make use of Unity Framework with Entity Framework. Let me explain the scenario. Let's say I have a Database with 5 tables. I will have 5 interfaces each of them corresponding to one table in Database having each field of table as a member. Now I want my Entity Framework generated classes to implement corresponding table interface. All navigational properties should return objects as interface references. This should allow me to resolve these entities using Unity framework to allow any one to extend EF(data) entities without breaking required code开发者_C百科s. Is this possible?


No there is no extensibility point for resolving entities with IoC container. EF will always handle instance creation of persisted entities. Morover EF mapping must work with classes not interfaces.

You can only handle ObjectMaterialized event on ObjectContext and provide some additional initialization of created entities.

You can try to add interfaces by implementing custom T4 template and including some convention (like name of the interface is always I + name of the entity) but still without IoC.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号