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 6122179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:52:07+00:00 2026-05-23T15:52:07+00:00

I just start using Ninject with MVC3 so here is my problem: – I

  • 0

I just start using Ninject with MVC3 so here is my problem:
– I installed Ninject 2.2.1.4 and Ninject.MVC3 2.2.2.0 from Nuget
– In my WebUI (MVC3 project):

Global.asax.cs

public class MvcApplication : NinjectHttpApplication
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "home", action = "index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

    protected override void OnApplicationStarted()
    {
        base.OnApplicationStarted();

        AreaRegistration.RegisterAllAreas();
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }

    protected override IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        kernel.Load(Assembly.GetExecutingAssembly());
        return kernel;
    }


}
  • In my Domain (class project), i have my LinQ to SQL datacontext, i want to load the context with the connection string from my Web.Config in my WebUI, so i have to pass the constructor parameter, i also have some services in my Domain project

    public class LotteryDataService
    {
        LinQ.WebDataContext _context;
    
        public LotteryDataService(LinQ.WebDataContext context)
        {
            _context = context;
        }
    
        public IEnumerable<LinQ.LotteryData> Get()
        {
            return _context.LotteryDatas.Take(10);
        }
    }
    

How to bind the datacontext with Ninject with constructor parameter (here is connection string)?

  • 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-23T15:52:08+00:00Added an answer on May 23, 2026 at 3:52 pm

    This is how you pass a constructor parameter. Ninject will resolve the constructor that matches the specified constructor arguments.

    public class DataModule : NinjectModule
    {
        public override void Load()
        {
            string connectionString = "...";
            Bind<WebDataContext>().ToSelf()
                .WithConstructorArgument("connection", connectionString);
        }
    }
    

    The first argument to .WithConstructorArgument() should be the name of the constructor parameter. This is fileOrServerOrConnection in the base class, but connection in derived class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here I am just about to start a big project using LINQ to
I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project
I just added the Ninject.MVC3 nuget package (v2.2.2.0) to my ASP.NET MVC 3 app.
I'm just learning how to do things, and want to start using some sort
I'm working on a project which is just about to start, and since I
I am using Ninject in MVC3 application. One of my resolvable dependencies makes use
I am a beginner in iOS development and have just start using the lasted
I just now start using knockoutjs. In below code am just trying to bind
I've just tried to start using PDO to handle database access in PHP. I
I am using MiniDFSCluster to do junit tests. Now I just start and close

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.