I have the following architecture where a public Service class referencing an internal Helper class exists in another assembly:
ApplicationAssembly {
public class Widget {
public Widget(ReferencedAssembly.Service service) { ... }
}
}
ReferencedAssembly {
public class Service {
public Service(Helper helper) { ... }
}
class Helper { ... }
}
(I realize that I can't put an internal class in the arguments of a public class's constructor--I'm just trying to illustrate the IoC pattern I'm going after.)
The problem is that ApplicationAssembly
can't see ReferencedAssembly.Helper
, so it can't be registered in my IoC container (Autofac in this case). As a result, Helper
cannot be resolved when I try to resolve Service
. What is my best option here?
Option 1: Remove
Helper
fromService
's constructor and new it up in the constructor explicitly. I don't like this option because it kind of breaks the IoC paradigm.Option 2: Make
Helper
implement a publicIHelper
interface, then add a public module withinReferencedAssembly
that registersHelper
as anIHelper
. I don't like this option because it requiresApplicationAssembly
to know too many implementation details aboutService
, and if the user forgets to register that module at startup everything breaks.Option 3: Create a public static constructor on
Service
that builds a 2nd IoC container specifically forReferencedAssembly
and registersHelper
in it. RemoveHelper
fromService
's constructor and resolve it within the constructor using the 2nd IoC container. This seems like my best option but requires more "plumbing" code than the others. I'm also not a big fan of public static constructors.Option 4. Change my architecture to something else altogether.