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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:40:45+00:00 2026-05-26T05:40:45+00:00

I know with Castle Windsor, you can register aspects (when using method interception in

  • 0

I know with Castle Windsor, you can register aspects (when using method interception in Windsor as AOP) using code instead of applying attributes to classes. Is the same possible in Postsharp? It’s a preference things, but prefer to have aspects matched to interfaces/objects in one place, as opposed to attributes all over.

Update:
Curious if I can assign aspects to interfaces/objects similiar to this:

container.Register(
        Component
        .For<IService>()
        .ImplementedBy<Service>()
        .Interceptors(InterceptorReference.ForType<LoggingAspect>()).Anywhere
   );

If you could do this, you would have the option of NOT having to place attributes on assemblies/class/methods to apply aspects. I can then have one code file/class that contains which aspects are applied to which class/methods/etc.

  • 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-26T05:40:45+00:00Added an answer on May 26, 2026 at 5:40 am

    Yes. You can either use multicasting (http://www.sharpcrafters.com/blog/post/Day-2-Applying-Aspects-with-Multicasting-Part-1.aspx , http://www.sharpcrafters.com/blog/post/Day-3-Applying-Aspects-with-Multicasting-Part-2.aspx) or you can use aspect providers (http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-12-e28093-Aspect-Providers-e28093-Part-1.aspx , http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-13-e28093-Aspect-Providers-e28093-Part-2.aspx).

    Example:

        using System;
        using PostSharp.Aspects;
        using PostSharp.Extensibility;
    
        [assembly: PostSharpInterfaceTest.MyAspect(AttributeTargetTypes = "PostSharpInterfaceTest.Interface1", AttributeInheritance = MulticastInheritance.Multicast)]
    
        namespace PostSharpInterfaceTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                Example e = new Example();
                Example2 e2 = new Example2();
                e.DoSomething();
                e2.DoSomething();
                Console.ReadKey();
            }
        }
    
        class Example : Interface1
        {
    
            public void DoSomething()
            {
                Console.WriteLine("Doing something");
            }
        }
    
        class Example2 : Interface1
        {
    
            public void DoSomething()
            {
                Console.WriteLine("Doing something else");
            }
        }
    
        interface Interface1
        {
            void DoSomething();
        }
    
        [Serializable]
        class MyAspect : OnMethodBoundaryAspect
        {
            public override void OnEntry(MethodExecutionArgs args)
            {
                Console.WriteLine("Entered " + args.Method.Name);
            }
        }
    }
    

    I recommend that if you have complex requirements for determining which types get certain aspects that you consider creating an aspect provider instead.

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

Sidebar

Related Questions

I am using a IoC Container (Castle Windsor) to instantiate classes accordingly to the
I know how to tell Castle Windsor to resolve a reference from a factory's
I'm really new to Castle Windsor IoC container. I wanted to know if theres
Does anyone know if there are new binaries for the castle logging facility using
Using Castle Windsor, I want to configure a generic service with a type parameter;
I am running into an issue when using my Castle Windsor Controller Factory with
Most of the examples I see for Castle Windsor auto-register type that derive from
I'm using Castle Windsor in my project. Some registered components are intercepted. Because the
Possible Duplicate: Where can I download the Castle Windsor WcfIntegration Facilities dll? I need
Does Castle Windsor support applying setter injection to existing service instances? I have 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.