In my project I had a controller dependency on IRepositoryProvider among others.
public class HomeController : BaseController
{
public HomeController(ISessionWrapper sessionWrapper,
IRepositoryProvider repositoryProvider,
IApplicationConfiguration applicationConfiguration)
: base(sessionWrapper, repositoryProvider, applicationConfiguration)
{}
...
}
IRepositoryProvider and its implementation live in a BLL layer. Another thing to note is that IRepositoryProvider has some parameters also. These are used to determine which connection strings to use (Environment*5 possible connections).
public RepositoryProvider(string environment, IApplicationConfiguration applicationConfiguration)
{
_applicationConfiguration = applicationConfiguration;
_environment = environment;
}
This all works fine with two layers and this Ninject config.
kernel.Bind<IRepositoryProvider>()
.To<RepositoryProvider>()
.InRequestScope()
.WithConstructorArgument("environment",
context => context.Kernel.Get<ISessionWrapper>().CurrentEnvironment)
.WithConstructorArgument("applicationConfiguration",
context => context.Kernel.Get<IApplicationConfiguration>());
My issue develops when I introduced a service layer. Instead of relying on IRepositoryProvider in my controllers for data access, I want to use the service layer. Ideally then I don't want to reference the BLL layer, and only the Service layer.
public class HomeService : IHomeService
{
public IRepositoryProvider RepositoryProvider { get; private set; }
public HomeService(IRepositoryProvider repositoryProvider)
{
RepositoryProvider = repositoryProvider;
}
...
}
So my question is this: Is it possible for me to not reference both the Service and BLL layers from the MVC project? Or is this whole setup a massive code smell?
Thanks.
UPDATE: I suppose I should have said my ideal references. Web -> Service -> BLL. At the moment Web references both Service and BLL in order for Ninject to resolve everything.
UPDATE 2: Does this seem like a possible solution? How to tell Ninject to bind to an implementation it doesn't have a reference to