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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:08:09+00:00 2026-06-12T02:08:09+00:00

I successfully wired Autofac in my ASP.NET WebAPI project, and now I am wondering

  • 0

I successfully wired Autofac in my ASP.NET WebAPI project, and now I am wondering how to be able to resolve services in my MessageHandlers.

As MessageHandlers have to be added at application startup, it’s clear that I won’t be able to resolve them in a request lifetime scope. No problem here.

However, I would like to find a way to get the current request lifetime scope during the execution of the SendAsync method of the MessageHandler, in order to be able to (for instance) perform token verification, logging in a repository, etc…

How should I do that?

  • 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-12T02:08:10+00:00Added an answer on June 12, 2026 at 2:08 am

    You can use the GetDependencyScope() extension method on the HttpRequestMessage which gives you an IDependencyScope from where you can resolve any service that you want in you handler:

    public class MyHandler : DelegatingHandler
    {
        protected override Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request, 
            CancellationToken cancellationToken)
        {
            IMyService myservice =
             (IMyService)request.GetDependencyScope().GetService(typeof(IMyService));
            // Do my stuff with myservice
            return base.SendAsync(request, cancellationToken);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully wired up a Facebook Connect application and everything is working fine.
We have been successfully using protobuf-net v1 in a compact framework application to handle
I have an ASP.NET MVC 3 app. I kind of understand routes, but then
Successfully used jquery-infinite-carousel in the past but for my current project I need it
After successfully acquiring an oauth_token for a user, I am able to get successful
This is my code: function get_remote_file_to_cache(){ $sites_array = array(http://www.php.net, http://www.engadget.com, http://www.google.se, http://arstechnica.com, http://wired.com); $the_site=
I am using jQuery Templates successfully but I have a blur function that is
I have successfully built a thin client/server using Qt's Tcp Sockets API. I know
I successfully implemented the OpenCV square-detection example in my test application, but now need
I'm building an asp.net mvc application for users to enter an essay contest. I

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.