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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:38:12+00:00 2026-06-09T12:38:12+00:00

I use autofac and can pass parameters to my resolve method. How can I

  • 0

I use autofac and can pass parameters to my resolve method.

How can I do this using microsofts DependencyResolver interface?

  • 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-09T12:38:13+00:00Added an answer on June 9, 2026 at 12:38 pm

    The IDependencyResolver does not support passing parameters directly, as I’m sure you have noticed. However, since you have Autofac under the hood, you’re able to resolve a factory delegate that enables you to pass on parameters to the underlying service:

    var factory = dependencyResolver.GetService<Func<int, string, IService>>();
    var service = factory(5, "42");
    

    Note: you can either use Func delegates or explicitly defined factory delegates. More on this here.

    Regarding lifetime scopes: factory delegates must be resolved from a scope where the requested service can be “reached”. Consider this setup simulating how MVC or WebApi would look like:

    var cb = new ContainerBuilder();
    cb.RegisterType<X>().InstancePerMatchingLifetimeScope("http");
    var application = cb.Build();
    var request = application.BeginLifetimeScope("http");
    

    With this setup, our X service will only be available in the http scope. Trying to resolve X from application scope will fail with this message:

    No scope with a Tag matching ‘http’ is visible from the scope
    in which the instance was requested.

    Resolving from the request scope will work as expected:

    var f = request.Resolve<Func<IX>>();
    var x = f();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way i can set AutoFac to use PropertiesAutowired(true) to be the
I have started to use Autofac following this tutorials: http://flexamusements.blogspot.com/2010/09/dependency-injection-part-3-making-our.html Simple class with no
I need to register my Autofac container with specific interface, for this case I
I can see how I can instantiate objects of classes using autofac, and then
In this Autofac IoC article they show an example of mapping an interface to
I am currently using/experimenting with autofac as my IoC controller. Previously to this I
I am trying to use Autofac and Autofac.Integrations.Web to register ASP.NET MVC controllers. I
I'm currently doing a bit of experimenting using Autofac-1.4.5.676, autofac contrib and castle DynamicProxy2.
I notice the latest alpha of SolrNet supports Autofac integration. This wiki page discusses
I currently use Autofac to do simple constructor injection without any issues. However what

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.