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

The Archive Base Latest Questions

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

I have a method in a class as follow that I want to intercept:

  • 0

I have a method in a class as follow that I want to intercept:

[CustomTag1(Order = 0)]
[CustomTag2(Order = 1)]
public virtual DoSomething()

How can I inject the order value into ICallHandler.Order property, when using CustomAttributeMatchingRule?

I don’t want the order to be hard coded to the handler itself or at registration. I want it to be a variable of the Order property of the method annotation.

  • 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-12T12:49:01+00:00Added an answer on June 12, 2026 at 12:49 pm

    I’ve achieved this using the HandlerAttribute – in general I use this anyway for attribute-style interception in Unity simply because you don’t have to bother creating policies manually – instead you just apply a HandlerAttribute to your code and Unity will automatically create a policy for you.

    Anyway, something like this is probably what you are after. First define a call handler as usual except parameterise it: –

    public class MyCallHandler : ICallHandler
    {
        public MyCallHandler(Int32 value)
        {
            Order = value;
        }
    
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            Console.WriteLine("Parameterised call handler!");
            return getNext()(input, getNext);
        }
    
        public int Order { get; set; }
    }
    

    Now instead of using the CustomTagAttribute, use a HandlerAttribute:-

    public class MyHandler : HandlerAttribute
    {
        private readonly Int32 value;
        public MyHandler(Int32 value)
        {
            this.value = value;
        }
    
        public override ICallHandler CreateHandler(IUnityContainer container)
        {
            return new MyCallHandler(value);
        }
    }
    

    The MyHandler is applied on your class. The CreateHandler method gets called, at which point it creates an instance MyCallHandler: –

    public class MyClass
    {
        [MyHandler(2)] // Order of 2
        public virtual void Foo()
        {
            Console.WriteLine("Inside method!");
        }
    }
    

    Note that I’ve deliberately separated the two classes but in reality you can just have one class implement both the ICallHandler interface and the HandlerAttribute abstract method (just return “this”).

    You could probably achieve something similar without the HandlerAttribute, using your own custom attribute, but it saves you time as you don’t need to mess around with creating your own policies.

    One thing to note – if you take a parameterised approach, you cannot have your call handlers as singletons, since a different instance will be created every time depending on what order you want it to be in.

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

Sidebar

Related Questions

I have a method in a class in another file that I want to
Assume that I have the follow class. class Foo # I want the following
So I have a class with a method as follows: public class SomeClass {
I have method in a class that I need to make sure is only
I have method that returns module path of given class name def findModulePath(path, className):
I have a class that might throw any run-time exceptions during initialization. I want
I have a method in a class as follows... class foo{ int bar::randomNum10to50(){ srand
I have a __new__ method as follows: class MyClass(object): def __new__(cls, *args): new_args =
I have a class with a static method modifying a static variable as follows,
I have a class with a custom each-method: class CurseArray < Array def each_safe

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.