I have a web app which is deployed on azure app service.
It has three layers.
API->Business->Data
API references assembly of Business layer ,Business layer references assembly of Data layer , (Which uses entity framework to do database transactions).
I am using Unity container to introduce dependency injection with web.config something like this.
<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>
In the controller constructor
var _container = new UnityContainer();
_container.LoadConfiguration();
This all works perfect in local with dependency injection.
however trouble starts when I deploy it to azure app service.
unity fails to load DALContext with the above config declaration. although Dll's are present in the AppService Bin directory.
Only after some troubleshooting did it strike me, that maybe it's because my Api project doesnt directly reference DataLayer DLL.
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.
Has anyone come across something like this?