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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:39:14+00:00 2026-05-28T01:39:14+00:00

I’m using Castle Windsor 3.0. I have a component that should be started automatically

  • 0

I’m using Castle Windsor 3.0.

I have a component that should be started automatically after the registration phase.
I would also like to intercept exceptions coming from it’s Start/Stop methods and log their details.

To make my component startable, I used the Startable facility that comes with Windsor:

container.AddFacility<StartableFacility>(f => f.DeferredStart());

I created a custom interceptor like this:

class ExceptionLoggerInterceptor : IInterceptor
{
    IExceptionLogger m_ExceptionLogger;

    public ExceptionLoggerInterceptor(IExceptionLogger exceptionLogger)
    {
        if (exceptionLogger == null)
            throw new ArgumentNullException("exceptionLogger");

        m_ExceptionLogger = exceptionLogger;
    }

    public void Intercept(IInvocation invocation)
    {
        try
        {
            invocation.Proceed();
        }
        catch (Exception ex)
        {
            m_ExceptionLogger.Write(ex, invocation.Method.Name, invocation.TargetType.Name);
        }
    }
}

and I registered the component like this:

Component.For<IExceptionLogger>()
 .ImplementedBy<EnterpriseLibraryExceptionLogger>()
 .LifeStyle.Singleton,

Component.For<ExceptionLoggerInterceptor>()
 .LifeStyle.Singleton,

Component.For<IWorkflowService>()
 .ImplementedBy<WorkflowService>()
 .LifeStyle.Singleton
 .StartUsingMethod(c => c.Start)
 .StopUsingMethod(c => c.Stop)
 .Interceptors(InterceptorReference.ForType<ExceptionLoggerInterceptor>()).Anywhere

To make a test, I coded a dirty

throw new Exception(); 

in the implementation of the Start method of the component. At registration phase, when Windsor automatically calls the Start method on the component, the exception is thrown, but never intercepted by my custom interceptor.

I made another test, this time without using the Startable facility but rather calling the Start method manually. The exception got thrown and was intercepted by my custom interceptor.

So, as the title of this post asks, is there a way to intercept methods called by the Startable facility with Windsor?

Regards

Louis-Pierre Beaumont

  • 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-28T01:39:15+00:00Added an answer on May 28, 2026 at 1:39 am

    I’m going to partially answer my own question:

    I did not find any way to intercept the Start method on a component when using the Startable facility. It looks like the facility is not using the proxy created for the object to perform the call, but the object itself.

    A dedicated post presents the problem here.

    Anyway, I quicly figured out that doing AOP with Proxy objects has it’s limits. That’s why I moved to SheepAspect, an IL Weaving AOP Framework.

    I mixed SheepAspect with Castle Windsor, and now, when my component’s Start method is called by the Castle Startable facility, all my aspects are also called!

    Here is how i wrote my ExceptionAspect with SheepAspect:

    [SingletonAspect]
    public class ExceptionAspect
    {
        IExceptionLogger m_ExceptionLogger;
    
        public ExceptionAspect(IExceptionLogger exceptionLogger)
        {
            if (exceptionLogger == null)
                throw new ArgumentNullException("exceptionLogger");
    
            m_ExceptionLogger = exceptionLogger;
        }
    
        [SelectTypes(typeof(WorkflowService))]
        void Targets() { }
    
        [Around("Execute")]
        [SelectMethods("Name:('Start') & InType:@Targets")]
        public void Execute(MethodJointPoint jp)
        {
            object result = null;
    
            try
            {
                result = jp.Execute();
            }
            catch (Exception ex)
            {
                m_ExceptionLogger.Write(ex, jp.Method.Name, jp.Method.ReflectedType.Name);
            }
    
            return result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.