Configuring Ninject for a console application and leveraging the existing repository for my MVC application

前端 未结 1 1187
抹茶落季
抹茶落季 2020-12-29 07:41

I have a MVC 3 solution configured with Ninject using a repository pattern. Some of my bindings include:

kernel.Bind().To

        
相关标签:
1条回答
  • 2020-12-29 08:12

    Do you want one and only one instance of each of your repository services for the whole application? If so, then use InSingletonScope.

    Is your console application multithreaded? If this is the case and you want a new instance of your services for each thread then you will use InThreadScope.

    If you want a new instance of the service(s) each time they are called for, set it to InTransientScope.

    You also have the option of defining your own scope using InScope. Bob Cravens gives a good overview of each of these here http://blog.bobcravens.com/2010/03/ninject-life-cycle-management-or-scoping/

    0 讨论(0)
提交回复
热议问题