2

I was trying Ninject in a Asp.net Mvc application and I was wondering what the best practice is for using Ninject if you have more than 1 project in your solution.

I guess all projects need some kind of Loader which you initialize in the global.asax?

Kind regards,

Pickels

2 Answers 2

1

In general you should only be bringing in an IoC container (in this case Ninject) in the actual executable (or ASP.NET application). Reusable libraries should be agnostic toward which container is used.

To use Ninject in an ASP.NET MVC application specifically, you should use the Ninject controller factory in the Ninject.Web.Mvc extension.

Sign up to request clarification or add additional context in comments.

5 Comments

I was already using Ninject.Web.Mvc but thanks for that tip anyway.
Do you have some information or a pattern that shows how I can have each library have it's own IoC container? The example code I started from uses the kernel from the domain library to also load the Ninject modules in the web project.
@Pickels: Each library doesn't have its own IoC container. That was my point - you only start using the IoC container at the last possible stage.
Exaclty, there only needs to be one IoC container per application, no matter how many projects it may be comprised of. This is set up in your entry point project.
Thanks for the info I really appreciate it. Going to do some testing and try to implement it this way.
1

Usually your IoC container is initialised and configured in your entry point project (the web project in your case). And yes, this would normally take place in (directly or indirectly) the global.asax. You shouldn't need to bother with config in any of the other projects though in most cases.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.