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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:51:54+00:00 2026-06-18T01:51:54+00:00

When using Ninject with ServiceStack, how would I specify that an object’s lifetime is

  • 0

When using Ninject with ServiceStack, how would I specify that an object’s lifetime is to be per-request, calling any IDisposable.Dispose method if necessary?

Per the docs, the default way of doing this is:

container.RegisterAutoWiredAs<MyType,IMyType>().ReusedWithin(ReuseScope.Request); 

However, I have to use the NinjectContainerAdapter for my project. Normally I’d install Ninject.Web.Common and write:

kernel.Bind<IMyType>().To<MyType>().InRequestScope()

and my instance would be disposed of at the end of the request. How would I go about doing this in ServiceStack, say in a self-hosted scenario?

  • 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-06-18T01:51:55+00:00Added an answer on June 18, 2026 at 1:51 am

    You will have to implement an INinjectHttpApplicationPlugin for ServiceStack. In the method object GetRequestScope(IContext context); you must return some object that has the lifetime of a request (an equivalent to HttpContext.Current))

    Probably you could add an object to HostContext and return that one as scope. Best you make that object implement INotifyWhenDisposed and dispose it at the end of the request so that the objects are released imediately after the request instead of waiting for the object to be garbage collected..

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

Sidebar

Related Questions

I am using Ninject to use the same database connection per request. We have
Using Ninject i would like to rebind one method to another implementation is that
I have a few classes that are instantiated using ninject Session Scoping - because
I am using Ninject for DI. I have Ninject Modules that bind some services
I am building a MVC3 app using Ninject framework. I have a service that
I'm trying to specify a connection string dynamically based of the url using ninject.
I'm using Ninject for a desktop application. I'm noticing that if I exit the
I'm using Ninject in my MVC 3 project and that works fine, but I
I'm using Ninject (3.0) in my ASP.Net MVC3 project. At some point of request
I've been using Ninject like so: ninjectKernel.<IBlogRepository>().To<BlogRepository>(); I would like a specific obejct to

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.