I am working on a small class library and using Simple Injector for my DI.
The class library has an access point (some sort of a service I guess) which is public
and it has some internal
services and repositories.
I saw that Simple Injector does not support constructor injection with internal constructors. For example, my product service looks like:
internal class ProductService : IProductService
{
private IProductRepository _productRepository;
internal ProductService(IProductRepository repository)
{
if (repository == null) throw new ArgumentNullException("repository");
_productRepository = repository;
}
}
And my setup:
container.Register<IProductService, ProductService>();
container.Register<IProductRepository>(() => new ProductRepository());
When I run the code, I get the following exception:
For the container to be able to create ProductService, it should contain exactly one public constructor, but it has 0.
My questions:
1) Is there a specific reason that injecting internal classes doesn't work in terms of architecture/design?
2) How is this behavior (using dependency injection with classes that should not be public) achieved and is it desired?