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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:22:50+00:00 2026-05-30T02:22:50+00:00

I am new to Spring.NET and am just playing around trying different things out.

  • 0

I am new to Spring.NET and am just playing around trying different things out. As part of my testing, I created a simple object:

public interface ICommand {
    void Execute(object context);
}

with one implementation:

public class ServiceCommand : ICommand {
    public ServiceCommand() {
        Console.WriteLine("########## {0} ##########", GetType().Name);
    }

    public void Execute(object context) {
        Console.WriteLine("Service implementation: {0}.{1}", GetType().Name, MethodBase.GetCurrentMethod().Name);
    }
}

Finally, I’ve a simple before advice as follows:

public class ConsoleLoggingBeforeAdvice : IMethodBeforeAdvice {
    public ConsoleLoggingBeforeAdvice() {
        Console.WriteLine("########## {0} ##########", GetType().Name);
    }

    public void Before(MethodInfo method, object[] args, object target) {
        Console.WriteLine("Intercepted call to this method: {0}", method.Name);
        Console.WriteLine("     The target is             : {0}", target);
        Console.WriteLine("     The arguments are         : ");
        if (args != null) {
            foreach (object arg in args) {
                Console.WriteLine("\t: {0}", arg);
            }
        }
    }
}

As you can see, much of this stuff is from the Spring.NET quick start samples.

So, I configured the ServiceCommand to be wrapped in a ConsoleLoggingBeforeAdvice via ProxyFactoryObject and marked both the objects as prototype (see config below). This works as expected: each time we request a ServiceCommand, a new instance of both the object and associated interceptor is created:

<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net">
    <object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false">
        <property name="Advice">
            <object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/>
        </property>
    </object>

    <object id="ServiceCommandTarget" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/>

    <object id="ServiceCommand" type ="Spring.Aop.Framework.ProxyFactoryObject">
        <property name="IsSingleton" value="false"/>
        <property name="TargetName" value="ServiceCommandTarget"/>
        <property name="InterceptorNames">
            <list>
                <value>ConsoleLoggingBeforeAdvice</value>
            </list>
        </property>
    </object>
</objects>

However, when I try to achieve the same results via DefaultAdvisorAutoProxyCreator, everything works except that the interceptor is always created as Singleton (even though it’s configured as singleton=”false”). The config is as follows:

<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net">
    <object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false">
        <property name="Advice">
            <object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/>
        </property>
    </object>

    <object id="ServiceCommand" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/>
    <object type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator"/>
</objects>

Now, how can I ensure that both the object and associated interceptor are treated as prototypes by DefaultAdvisorAutoProxyCreator?

  • 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-30T02:22:52+00:00Added an answer on May 30, 2026 at 2:22 am

    OK, I’ve figured out that setting InterceptorNames on DefaultAdvisorAutoProxyCreator will correctly instantiate interceptors as prototypes (if they’re configured so). But this somehow feels incorrect as the DefaultAdvisorAutoProxyCreator should be able to pick interceptors from advisors and honor their configuration settings.

    I am still not 100% clear on how to create prototype interceptors under different scenrarios. For example, all my attempts to create thread-scoped interceptors while using DefaultAdvisorAutoProxyCreator have failed.

    Anyways, here’s the xml config that works for me:

    <?xml version="1.0" encoding="utf-8"?>
    <objects xmlns="http://www.springframework.net" default-autowire="constructor">
        <object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false">
            <property name="Advice">
                <object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/>
            </property>
        </object>
    
        <object id="ServiceCommand" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/>
    
        <object type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator">
            <property name="InterceptorNames" value="ConsoleLoggingBeforeAdvice"/>
        </object>
    </objects>
    

    I am totally confused with the idea of creating prototype interceptors. Are interceptors supposed to be or recommended to be prototypes at all or should they always be singletons?

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

Sidebar

Related Questions

Just playing around with some of the APIs in .NET and I can't seem
I'm playing around with .net 4's System.Windows.Markup.XamlReader - just as an education exercise -
Just playing around with the PayPal API, trying to implement Checkout Express so I
I'm new with JSON.NET and I'm trying to deserialize a JSON string to a
I m very new in spring batch project.I m trying to create a project
I'm new to Spring and trying to use the Spring Formatting SPI for UI
I'm trying to write a simple PHP script which automatically sets up new etherpads
Hoho there. I was just trying to enhance the performance of my application (.NET
I've been playing around with ASP.NET MVC with a site containing a Master Page.
So I was playing around a little more with attributes in .NET, and realized

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.