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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:40:49+00:00 2026-06-16T05:40:49+00:00

I have the following code: _container = new Container(x => x.AddRegistry<ManagerRegistry>()); – public class

  • 0

I have the following code:

_container = new Container(x => x.AddRegistry<ManagerRegistry>());

–

public class ManagerRegistry : Registry
{
    public ManagerRegistry()
    {
        var proxyGenerator = new ProxyGenerator();

        For<IPersonManager>()
            .EnrichAllWith(t => proxyGenerator.CreateInterfaceProxyWithTarget(
                                t, new AuthenticationInterceptor()))
            .Use<PersonManager>();
    }
}

–

public class AuthenticationInterceptor : IInterceptor
{
    public void Intercept(IInvocation invocation)
    {
        if (!HttpContext.Current.User.IsInRole("Monkey"))
            throw new Exception("Only monkeys allowed!");

        invocation.Proceed();
    }
}

It interceps the creation of a dependency in StructureMap, and decorates it using DynamicProxy.
Now this works fine, because the interceptor has no dependencies itself.

But given the following:

public class LoggingInterceptor : IInterceptor
{
    public LoggingInterceptor(ILogger logger)
    {

How would I go about wiring that up in StructureMap?

  • 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-16T05:40:50+00:00Added an answer on June 16, 2026 at 5:40 am

    This is what I came up with:

    _container.RegisterInterceptor<IPersonManager, LoggingInterceptor>();
    

    –

    public static class ContainerExtensions
    {
        public static void RegisterInterceptor<TDependency, TInterceptor>(this IContainer container)
            where TDependency : class
            where TInterceptor : IInterceptor 
        {
            IInterceptor interceptor = container.GetInstance<TInterceptor>();
    
            if (interceptor == null)
                throw new NullReferenceException("interceptor");
    
            TypeInterceptor typeInterceptor 
                = new GenericTypeInterceptor<TDependency>(interceptor);
    
            container.Configure(c => c.RegisterInterceptor(typeInterceptor));
        }
    }
    

    –

    public class GenericTypeInterceptor<TDependency> : TypeInterceptor
        where TDependency : class
    {
        private readonly IInterceptor _interceptor;
        private readonly ProxyGenerator _proxyGenerator = new ProxyGenerator();
    
        public GenericTypeInterceptor(IInterceptor interceptor)
        {
            if (interceptor == null)
                throw new ArgumentNullException("interceptor");
    
            _interceptor = interceptor;
        }
    
        public object Process(object target, IContext context)
        {
            return _proxyGenerator.CreateInterfaceProxyWithTarget(target as TDependency, _interceptor);
        }
    
        public bool MatchesType(Type type)
        {
            return typeof(TDependency).IsAssignableFrom(type);
        }
    }
    

    I’m pretty happy with the result.

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

Sidebar

Related Questions

I have the following code :- class A : public B { public: _container
I have the following code var container = new UnityContainer(); //LINE 1 container.RegisterType<ILogUtility,LogUtil>(); //LINE
I have the following code: $(document).ready(function() { $('.container').ready(function() { var v = new Video($(this));
I have the following code: _container = new UnityContainer(); _container.RegisterType<IDownloader, Downloader>(); _container.RegisterType<INewObject, NewObject>(); _container.RegisterType<SearchViewModel>();
I have the following code in a class library: public class Manager { private
I have the following code: public interface IService { } public class MyService :
If I have the following code [Serializable] public abstract class ValidatedCommandArgs { } public
I have the following example code using MEF: public interface IFoo<T> {} public class
I have the following code: public class MessageEndpoint : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization { private
I have the following code: IOC.Container.RegisterType<IRepository, GenericRepository> (Customers, new InjectionConstructor(new CustomerEntities())); What I am

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.