Why Unity Needs Assembly Links

I find out unexpected behavior when using a Unity application block. I have Project A as my initial project.

Project A has a link to Project B, which has a link to Project C.

Project A uses unity to allow references to classes defined in project B. These classes, in turn, use Unity to resolve references to dependencies on classes in project C.

So, since I only use interfaces defined in the general project and allowing specific references using Unity, there is no need to add project / assembly references for Project B or Project C in Project A.

But in this case, Unity cannot resolve the links. If, on the other hand, I add links for both projects, there is no problem. Why is this necessary? Is there any way around this?

Is it because Unity would need the dll to be in context and loaded to create types from these assemblies? . Somehow this is not so. Can someone help me in understanding this beahvior.

+4
source share
2 answers

The code in the Unity assembly should be able to resolve specific classes that you registered. This means that it must have access to the assemblies in which the specific classes are located - either in the same output directory as the Unity assembly, or in the GAC unity in order to be able to find them.

+1
source

If you register dependencies in code, you need to reference the assemblies in which these dependencies are defined (whether it be interfaces or specific classes). If you define mappings in XML, you don't need references, but you need to make sure that Unity can find assemblies at runtime. Therefore, you need to either put them in the GAC or in the application folder.

+3
source

Source: https://habr.com/ru/post/1416573/


All Articles