In my solution I have an IoC container (Ninject) in its own module. It works fine to resolve dependencies between public classes of all modules, but how could it resolve dependencies of internal classes?
I have a public class called Customer
, in the BusinessRules project. Before saving a new customer, many validation methods must be called, and they're all in an internal class called CustomerValidator
. This validator class is an implementation detail and should be called only to validate a new customer, so no other project should see it.
The problem is that the IoC Container can't see the CustomerValidator
(since it's internal), and it can't resolve a dependency like this:
public class Customer(ICustomerValidator customerValidator)
{
//...
}
The IoC container can see only the public Customer
class, but knows nothing about the existence of the internal CustomerValidator
class. One possible solution is to use the InternalsVisibleTo attribute, commonly used for unit tests, and then the IoC would be able to see my internal classes:
[assembly: InternalsVisibleTo("MySolution.IoC")]
Is that an acceptable solution? Are there any other ways of doing it while keeping the CustomerValidator internal?