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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:44:13+00:00 2026-05-20T18:44:13+00:00

I have the following registration builder.Register<Func<Type, IRequestHandler>>( c => request => (IRequestHandler)c.Resolve(request)); Basically I

  • 0

I have the following registration

builder.Register<Func<Type, IRequestHandler>>(
          c => request => (IRequestHandler)c.Resolve(request));

Basically I am trying to register a factory method that resolves an instance of IRequestHandler from a given type.

This works fine until the version 2.4.3.700. But now I am getting a the following error..

Cannot access a disposed object.
Object name: ‘This resolve operation has already ended. When
registering components using lambdas,
the IComponentContext ‘c’ parameter to
the lambda cannot be stored. Instead,
either resolve IComponentContext again
from ‘c’, or resolve a Func<> based
factory to create subsequent
components from.’.

UPDATE

I was trying to limit autofac’s exposure to the rest of the projects in the solution. Nick, thanks for the hint, now my registration looks like this…

 builder.Register<Func<Type,IRequestHandler>>(c =>  
         { 
           var handlers = c.Resolve<IIndex<Type,RequestHandler>>(); 
           return  request => handlers[request];  
         });
  • 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-20T18:44:14+00:00Added an answer on May 20, 2026 at 6:44 pm

    The c in this expression is a temporary, so this code while previously functional, is broken. Autofac 2.4.5 detects this problem while earlier versions silently ignored it.

    To fix the issue, explicitly resolve IComponentContext:

    builder.Register<Func<Type, IRequestHandler>>(c => {
        var ctx = c.Resolve<IComponentContext>();
        return request => (IRequestHandler)ctx.Resolve(request));
    });
    

    The functionality you’re emulating here might be better represented using keys and indexes, e.g. see Interrupted chain of IoC or http://code.google.com/p/autofac/wiki/TypedNamedAndKeyedServices.

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

Sidebar

Related Questions

I have the following facebook registration plugin that lets user register through their FB
I have a registration form that is rendered by the following urlconf -- url(r'^$',
I have the following registration: container.Register(AllTypes.FromAssemblyContaining<ITabViewModel>().BasedOn<ITabViewModel>()); Two classes: public class StructureDecorationViewModel : NotificationObject, ITabViewModel
I have the following area route registration method: /// <summary> /// Registers the area.
I have the following content types: Camp - the top level type Registration Information
I am trying to create a simple registration form. I have the following: include('User.datatype.php');
I have the following error: Notice: Undefined index: submit in C:\wamp\www\registration\register.php on line 6
I am trying to write code for registration form which have the following fields.
Hi I have the following code: <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <title>Registration Form</title>
I have a registration page with the following code below: in the views: def

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.