I have a solution with a MVC Web Project, Infrastructure project, Services project and Data project. I installed ninject from NuGet in Visual Studio. It created a folder in my Web project called "App_Start" and put the Ninject code file in there and my application works completely fine.

My problem is that I have a need to resolve a dependency outside the web project that is a property or in a constructor.

I have tried this in one of my classes in my services project:

    var m_customerService = DependencyResolver.Current.GetService(typeof(ICustomerService));

This returns null every single time. When I try this exact same thing in my HomeController for example, it returns exactly what I expect.

I suspect that it has something to do with how the projects are referencing each other. My Web project obviously references all the other projects. I thought about moving the Ninject start up code to my Infrastructure project so that I will have access to it anywhere. Does that make sense to do? Has anybody else had this problem or is there something that I am missing?

Any help on this would awesome. Thanks.

有帮助吗?

解决方案

I have fixed the issue. I moved Ninject to another project that spans all the projects in my solution and my service classes seem to by working correctly now.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top