Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:02:53+00:00 2026-05-23T14:02:53+00:00

I have a MVC 3 solution configured with Ninject using a repository pattern. Some

  • 0

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

kernel.Bind<IDatabaseFactory>().To<DatabaseFactory>().InRequestScope();
kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
kernel.Bind<IMyRepository>().To<MyRepository>().InRequestScope();
kernel.Bind<IMyService>().To<MyService>().InRequestScope();
kernel.Bind<ILogging>().To<Logging>().InSingletonScope();

I also added a console application to my solution and I want to leverage the same repository and services. My Ninject configuration for the console application looks like:

kernel.Bind<IDatabaseFactory>().To<DatabaseFactory>().InSingletonScope();
kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InSingletonScope();
kernel.Bind<IMyRepository>().To<MyRepository>().InSingletonScope();
kernel.Bind<IMyService>().To<MyService>().InSingletonScope();
kernel.Bind<ILogging>().To<Logging>().InSingletonScope();

My console code looks like:

static void Main(string[] args)
{
    IKernel kernel = new StandardKernel(new IoCMapper());

    var service = kernel.Get<IMyService>();
    var logger = kernel.Get<ILogging>();

    ... do some processing here
}

This works just fine but I want t be sure that I am configuring Ninject correctly for a console application. Is it correct to use InSingletonScope() for all my bindings in my console application? Should I be configuring it differently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:02:54+00:00Added an answer on May 23, 2026 at 2:02 pm

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC-based site, which is using a Repository/Service pattern for data access.
We have an ASP.Net MVC 1.0 solution developed using Visual Studio 2008 and .net
I have a website built in asp.net mvc 3 which uses the repository pattern
I have a website (MVC) and some other projects in the same solution. In
I am making an asp.net mvc solution with globalization. I have implemented globalization using
Going mad now. I have a MVC solution that i've upgraded from MVC 1
We have an ASP.Net MVC solution built in VS2008 and TFS2008. We use TFS
Does anyone have the issue with Resharper where opening a solution with MVC projects
I have a new solution that is an ASP.NET MVC 2.0 application. I have
I have a Solution with several projects in it, including two asp.net mvc projects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.