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

The Archive Base Latest Questions

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

How can I register global callback on Autofac container which is triggered whenever any

  • 0

How can I register global callback on Autofac container which is triggered whenever any object is resolved?

I want to use reflection and check if an object has a method called Initialize() and call it if it does. I want it to be duck typed i.e. no interfaces are required.

Thanks!

  • 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-09T02:17:02+00:00Added an answer on June 9, 2026 at 2:17 am

    In Autofac you can use the IComponentRegistration interface to subscribe on various lifetime events:

    • OnActivating
    • OnActivated
    • OnRelease

    You can get the IComponentRegistration instance by creating a Module and override the AttachToComponentRegistration method:

    public class EventModule : Module
    {
        protected override void AttachToComponentRegistration(
            IComponentRegistry componentRegistry, 
            IComponentRegistration registration)
        {
            registration.Activated += OnActivated;
        }
    
        private void OnActivated(object sender, ActivatedEventArgs<object> e)
        {
            e.Instance.GetType().GetMethod("Initialize").Invoke(e.Instance, null);
        }
    }
    

    Now you only need to register your module in your container builder:

    var builder = new ContainerBuilder();
    builder.RegisterModule<EventModule>();
    

    and the OnActivated method will be called after every component activation no mater in which module you have registered the component.

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

Sidebar

Related Questions

I want to make a WCF timer service where clients can register in order
I want to build a web application where users can register and have a
How can I register a Visual Basic 6.0 DLL file in the global assembly
I got a VirtualPathProvider which I register with HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider()) in global.asax. The FileExists
a conceptual question: I have a global system which sales agents use to write
I'm new with xcode developing. I can't find any free and easy-to-use translator on
i search for a method to register for a global hotkey, so i can
If i remember correctly in .NET one can register global handlers for unhandled exceptions.
I can register my android app with C2DM successfully using a <receiver> in my
I made a form so that users can register their email address for a

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.