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

  • Home
  • SEARCH
  • 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 6802091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:10:51+00:00 2026-05-26T19:10:51+00:00

I have just started using Unity and the interception capabilities. I created a prototype

  • 0

I have just started using Unity and the interception capabilities. I created a prototype to verify the limitation or capabilities and it seems to me that in order to intercept a method there are several condition that must be met. In particular it seems to me that the class or interface must be resolved through the container. Is that correct? Is there any method out there that let’s me do this without this requirement.

I may be misinterpreting how to use this properly as there is alot of older and partial information out there without good working examples.

I will update with some code. Please keep in mind there are thousands upon thousands of lines of code in this thing so changing this bad design is not an option and out of scope of this current project.


    public interface IApoClass
    {
        [LoggingCallHandler]
        void SomeAbstractAopMethod(string abstractparam);
        [LoggingCallHandlerAttribute]
        void SomeVirtualAopMethod(string virtualparam);
    }
    public abstract class AbstractAopClass : IApoClass
    {
        public abstract void SomeAbstractAopMethod(string whatthe);
        public virtual void SomeVirtualAopMethod(string abstractparam)
        {
            //essentiall do nothing
            return;
        }
    }
    public class NonAbstractAopMethod : AbstractAopClass
    {
        public override void SomeAbstractAopMethod(string whatthe)
        {
            Console.Write("I am the only enforced method");
        }
    }

The container:

            container.AddNewExtension<Interception>();
        //container.Configure<Interception>().SetInterceptorFor<IFrameworkInterceptionTest>(new InterfaceInterceptor());
        container.Configure<Interception>().SetInterceptorFor<IApoClass>(new InterfaceInterceptor());

The calling code:

        //resolve it despite it not having and definition, but we've wired the container for the interface implemented by the abstract parent class
        var nonabstractmethod = DependencyResolver.Current.GetService<NonAbstractAopMethod>();  
        nonabstractmethod.SomeAbstractAopMethod("doubt this works");
        nonabstractmethod.SomeVirtualAopMethod("if the above didn't then why try");
  • 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-26T19:10:51+00:00Added an answer on May 26, 2026 at 7:10 pm

    Your assumption is correct: if you wish to use interception you need to resolve the object through the container so Unity can create a proxy object or return a derived type.

    Unity Interception Techniques does a good job of explaining how it works.

    If I understand you correctly, you want to perform interception for interface methods while minimizing changes to the existing system.

    You should be able to wire up the interception. First register the interface and the concrete type you want to map to and then set the interception:

    IUnityContainer container = new UnityContainer();
    
    container.AddNewExtension<Interception>();
    
    container.RegisterType<IApoClass, NonAbstractAopMethod>()
                .Configure<Interception>()
                .SetInterceptorFor<IApoClass>(new InterfaceInterceptor());
    
    DependencyResolver.SetResolver(new UnityServiceLocator(container));
    
    var nonabstractmethod = DependencyResolver.Current.GetService<IApoClass>();
    nonabstractmethod.SomeAbstractAopMethod("doubt this works");
    nonabstractmethod.SomeVirtualAopMethod("if the above didn't then why try");
    

    If you need to map the interface to multiple concrete types you can do that by using a name:

    container.RegisterType<IApoClass, NonAbstractAopMethod2>(
            typeof(NonAbstractAopMethod2).Name)
        .Configure<Interception>()
        .SetInterceptorFor<IApoClass>(
            typeof(NonAbstractAopMethod2).Name, 
            new InterfaceInterceptor()
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using SVN, and I have a cache directory that I don't
I just started using Qt and noticed that all the example class definitions have
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started using Google Chrome , and noticed in parts of our site,
I have just started using silverlight 2 beta and cannot find how to or
I have just started using Boost 1.36. These libraries would be very useful in
i have just started using Moq ver (3.1) and i have read blogs and
I have just started using jQuery and although following code gets the job done,
I have just started using the Data Access Application Block from microsoft. There are
I just started using php arrays (and php in general) I have a code

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.