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

  • SEARCH
  • Home
  • 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 7410059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:10:30+00:00 2026-05-29T06:10:30+00:00

First, I have a dbcontext factory which is defined public class DatabaseFactory : Disposable,

  • 0

First, I have a dbcontext factory which is defined public class DatabaseFactory : Disposable, IDatabaseFactory and it just creates a context if one doesn’t already exist.

Next, I have a generic repository that is defined public class Repository<T> : IRepository<T>
where T : class
which takes the factory in the constructor. I have other concrete repositories that inherit from this one.

I also have a unit of work class that is defined public class UnitOfWork : IUnitOfWork which takes the factory in the constructor and saves all changes to the context inside the factory (which all repositories should be using).

In my controller, I have the constructor set as public ProjectController(IDatabaseFactory factory, IUnitOfWork unitOfWork, IProjectRepository projectRep, IUserRepository userRep).

Basically, I need the same instance of the factory to be passed to the unit of work and all repositories. With ninject, it creates a new factory for each object instead of passing a single instance to them all. Is there a way to only allow the single instance to be passed via ninject or am I not creating my factory correctly and/or not understanding ninject correctly?

Here are my bindings in ninject:

kernel.Bind<IProjectRepository>().To<ProjectRepository>();
kernel.Bind<IIssueRepository>().To<IssueRepository>();
kernel.Bind<IUserRepository>().To<UserRepository>();
kernel.Bind<IDatabaseFactory>().To<DatabaseFactory>();
kernel.Bind<IUnitOfWork>().To<UnitOfWork>();
  • 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-29T06:10:31+00:00Added an answer on May 29, 2026 at 6:10 am

    This happens because by default Ninject uses the Transient scope – which creates a new instance every time a type is requested.

    More info: https://github.com/ninject/ninject/wiki/Object-Scopes

    You should specify the scope depending on the actual usage of a particular instance of a type throughout your application:

    Example could look like this:

    kernel.Bind<IDatabaseFactory>().To<DatabaseFactory>().InSingletonScope();
    kernel.Bind<IUserRepository>().To<UserRepository>().InRequestScope();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a repository class which is querying the EF DbContext like this: public
I have defined some models like this (Entity Framework Code-First): public class A {
I have a code first model: namespace InternetComicsDatabase.Models { public class Issue { [Key]
I have two simple classes generated by code first. public class Company { public
Using VS2010, .NET4.0, MVC3, EF4.1 Code-First I have this POCO entities: public class XBLContent
I have an instance of a class called AccessData, which inherits from DbContext. So
I'm trying out Entity Framework Code first CTP4. Suppose I have: public class Parent
I have first names stored in one table and last names stored in another.
I have my first professional assignment of making a website in which a photographer's
the problem is that I first have to convert the two-dim to a one-dim,

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.