NInject: Where do you keep your reference to the Kernel?

后端 未结 3 717
终归单人心
终归单人心 2021-01-30 06:43

I\'m using NInject on a new web application and there are two things that are unclear to me:

  1. Don\'t I need to keep a reference to the Kernel around (Session/App

3条回答
  •  庸人自扰
    2021-01-30 07:29

    This is a common pitfall when starting to use a IoC container. See this related question.

    In a nutshell:

    • It's bad practice to pass your container around (been there, done that, and it really hurts)
    • If you really need to invocate directly the container, first consider abstracting to an injected factory, then as a last resource consider using a static gateway to the container

提交回复
热议问题