4

I have application called Company.Application. It does uses libraries:

  • Company.InversionOfControl
  • Company.Functionality.Contracts
  • Company.Functionality

The application uses InversionOfControl to scout the assemblies part app domains using:

appDomain.GetAssemblies()

The problem is that the Company.Application never references code from Company.Functionality directly but relies on interfaces defined in Company.Functionality.Contracts and Company.InversionOfControl to couple the functionality defined Company.Functionality and inject it in Company.Application

Because of this sometimes the application's domain does not sees the assembly Company.Functionality (ie appDomain.GetAssemblies() ).

My question is - is there way to force including of Company.Functionality ?

  • What do you mean by "add to the final bundle"? – DavidG Jul 22 '15 at 09:55
  • Use a post-build copy command. See this question http://stackoverflow.com/questions/4606670/c-sharp-copy-dlls-to-the-exe-output-directory-when-using-dependency-injection – Kevin Jul 22 '15 at 09:57
  • Is this a _ClickOnce_ app? –  Jul 22 '15 at 10:00
  • @Kevin Or just set the build directory to be the bin folder of `Company.Application` – DavidG Jul 22 '15 at 10:00
  • Edited the original post. By "add to the final bundle" I did mean that appDomain.GetAssemblies() does not lists Company.Functionality assembly even though referenced in the project – Vladimir Moushkov Jul 27 '15 at 15:52

2 Answers2

1

The only solution I have found is to do dummy line like:

var t = new[] {typeof(Company.Functionality.FirstClass)}

in Company.Application's initialization.

This will force the compiler to include the assembly. However this require managing of those lines.

  • This defeats the purpose of IoC if the client assembly must directly reference the implementation assembly. –  Jul 22 '15 at 09:59
  • @MickyDuncan I wouldn't say it defeats the object of IoC but it is a nasty hack that isn't needed. – DavidG Jul 22 '15 at 10:04
  • Indeed it is bad and that is the main point of having this posting. However unfortunately this seems the only reason to anonymously used assemblies will be part of the AppDomain. – Vladimir Moushkov Jul 27 '15 at 15:47
1

Usually the root should know everything to build up context. If this done dinamically than the IoC library should be parameterised to load the assembly to the app domain by code. If this not the case you have to load it manually via AppDomain.LoadFrom. Most container I saw require a place where both abstraction and implementation is referenced and visible to create the binding.

Péter
  • 2,161
  • 3
  • 21
  • 30