How can I force C# build process to include assemb

2019-02-25 18:19发布

问题:

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 ?

回答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.



回答2:

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.