Unity 找不到引用的 Dll
Unity does not find referenced Dll's
我有一个部署在 Azure 应用服务上的 Web 应用。
它有三层。
API->业务->数据
API 引用业务层的组件,业务层引用数据层的组件,(使用 entity framework 进行数据库事务)。
我正在使用 Unity 容器引入依赖注入,web.config 类似这样。
<unity>
<!-- lifetimes -->
<alias alias="singleton" type="Unity.Lifetime.ContainerControlledLifetimeManager, Unity.Abstractions" />
<alias alias="transient" type="Unity.Lifetime.TransientLifetimeManager, Unity.Abstractions" />
<alias alias="perThread" type="Unity.Lifetime.PerThreadLifetimeManager, Unity.Abstractions" />
<alias alias="externallyControlled" type="Unity.Lifetime.ExternallyControlledLifetimeManager, Unity.Abstractions" />
<!-- injection -->
<containers>
<container>
<types>
<register type="DALContextInterface, DALInterfaceAssembly" mapTo="DALContextClass, Assembly">
<lifetime type="perThread" />
</register>
<register type="BusinessLayerManagerInterface, Assembly" mapTo="BusinessLayer, Assembly">
<lifetime type="perThread" />
<property name="Db" dependencyType="DALContextClass, Assembly" />
</register>
<register type="IHomeController, Assembly" mapTo="HomeController, Assembly">
<lifetime type="singleton" />
</register>
</types>
</container>
</containers>
</unity>
在控制器构造函数中
var _container = new UnityContainer();
_container.LoadConfiguration();
这一切在依赖注入的本地完美运行。
然而,当我将它部署到 Azure 应用程序服务时,麻烦就开始了。
unity 无法使用上述配置声明加载 DALContext。
尽管 Dll 存在于 AppService Bin 目录中。
只有在一些故障排除之后才让我印象深刻,这可能是因为我的 Api 项目没有直接引用 DataLayer DLL。
当我在 api 项目中直接引用 DataLayer dll 时,它开始在 appservice 上运行得很好。
虽然这是一个肮脏的解决方法。我觉得很奇怪,Unity 无法找到 api 项目没有直接引用的 dll。
有人遇到过这样的事情吗?
Has anyone come across something like this?
XML 配置被认为是配置 DI 容器的过时方法。这种配置非常脆弱,不提供编译时类型检查,因此比在代码中配置更难维护。所以,是的,许多人已经 运行 参与其中,因此改变了他们配置容器的方式。
在这种特殊情况下,早在您将应用程序部署到服务器之前,编译器就会在您的开发机器上为您发现这一点。
When i directly referred DataLayer dll in the api project, it all starts working on appservice very well.
Although it's a dirty workaround. I find it strange, that Unity can't find dll's that are not directly referenced by the api project.
不,这不是肮脏的解决方法。 assembly containing the composition root to reference all layers of the application.
是正常的
我有一个部署在 Azure 应用服务上的 Web 应用。
它有三层。
API->业务->数据
API 引用业务层的组件,业务层引用数据层的组件,(使用 entity framework 进行数据库事务)。
我正在使用 Unity 容器引入依赖注入,web.config 类似这样。
<unity>
<!-- lifetimes -->
<alias alias="singleton" type="Unity.Lifetime.ContainerControlledLifetimeManager, Unity.Abstractions" />
<alias alias="transient" type="Unity.Lifetime.TransientLifetimeManager, Unity.Abstractions" />
<alias alias="perThread" type="Unity.Lifetime.PerThreadLifetimeManager, Unity.Abstractions" />
<alias alias="externallyControlled" type="Unity.Lifetime.ExternallyControlledLifetimeManager, Unity.Abstractions" />
<!-- injection -->
<containers>
<container>
<types>
<register type="DALContextInterface, DALInterfaceAssembly" mapTo="DALContextClass, Assembly">
<lifetime type="perThread" />
</register>
<register type="BusinessLayerManagerInterface, Assembly" mapTo="BusinessLayer, Assembly">
<lifetime type="perThread" />
<property name="Db" dependencyType="DALContextClass, Assembly" />
</register>
<register type="IHomeController, Assembly" mapTo="HomeController, Assembly">
<lifetime type="singleton" />
</register>
</types>
</container>
</containers>
</unity>
在控制器构造函数中
var _container = new UnityContainer();
_container.LoadConfiguration();
这一切在依赖注入的本地完美运行。
然而,当我将它部署到 Azure 应用程序服务时,麻烦就开始了。
unity 无法使用上述配置声明加载 DALContext。 尽管 Dll 存在于 AppService Bin 目录中。
只有在一些故障排除之后才让我印象深刻,这可能是因为我的 Api 项目没有直接引用 DataLayer DLL。
当我在 api 项目中直接引用 DataLayer dll 时,它开始在 appservice 上运行得很好。
虽然这是一个肮脏的解决方法。我觉得很奇怪,Unity 无法找到 api 项目没有直接引用的 dll。
有人遇到过这样的事情吗?
Has anyone come across something like this?
XML 配置被认为是配置 DI 容器的过时方法。这种配置非常脆弱,不提供编译时类型检查,因此比在代码中配置更难维护。所以,是的,许多人已经 运行 参与其中,因此改变了他们配置容器的方式。
在这种特殊情况下,早在您将应用程序部署到服务器之前,编译器就会在您的开发机器上为您发现这一点。
When i directly referred DataLayer dll in the api project, it all starts working on appservice very well.
Although it's a dirty workaround. I find it strange, that Unity can't find dll's that are not directly referenced by the api project.
不,这不是肮脏的解决方法。 assembly containing the composition root to reference all layers of the application.
是正常的