【发布时间】:2019-09-05 22:57:44
【问题描述】:
我有一个分层架构 [ WebAPI -> Logic -> Repository ],所以 WebAPI 不知道存储库层。我使用 Unity 进行依赖注入,因此没有直接引用其他层。
Repository 层的实现使用 Entity Framework,EntityFramework 程序集存在于其“/bin/Release”中
我为每个层都有一个项目,用于处理向 Unity 注册服务,并且 EntityFramework 程序集也存在于它的“/bin/Release”中。
要加载依赖项,我会使用 Assembly.LoadFrom 加载注册项目,因此它也会加载其依赖项。
不幸的是,这不起作用。 DbContext 构造函数抛出:
System.TypeInitializationException: 'The type initializer for
'System.Data.Entity.Internal.AppConfig' threw an exception.'
FileNotFoundException: Could not load file or assembly 'EntityFramework,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of
its dependencies.
我尝试将“configSections”和“entityFramework”复制到 WebAPI.config,尽管我怀疑它不起作用(它没有)。
我在这里得到的是,上下文会执行某种延迟绑定,因此它会在 WebAPI 引用中查找组件。 _有没有办法在注册或实施项目中使用它们?
我知道在 WebAPI 中安装 EntityFramework 会起作用,但我不想这样做。还有其他方法吗?
【问题讨论】:
标签: c# asp.net entity-framework asp.net-web-api