updating RegisterType

Aug 29, 2011 at 8:25 AM


most of our registrations are like:

            container.RegisterType<IBankAccount, BankAccount>();

 

however now we plan on using aop with unity and need to update our registrations to:

            container = new UnityContainer();
            container.AddNewExtension<Interception>();
            container.RegisterType<IBankAccount, BankAccount>(
                new Interceptor<InterfaceInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>()
            );

 

I would like to globally be able to update all the registration types to have

new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<PolicyInjectionBehavior>()

is there a way to update the registration programmatically to achieve this?

Aug 30, 2011 at 8:01 AM

Hi,

I'm afraid there is no other way than specifying them for every type registration. 

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 31, 2011 at 7:02 AM
Edited Aug 31, 2011 at 7:03 AM

You could do it in a loop, however. Something like this:

 

foreach(var r in container.Registrations) {
    container.RegisterType(r.RegisteredType, r.Name,
        new Interceptor<InterfaceInterceptor>(),
        new InterceptionBehavior<PolicyInjectionBehavior>());
}

Something like that, anyway. This works because the registration is setting separate things, and so it transparently adds to the container configuration, and doesn't override / replace the other information you've already built in.

Sep 4, 2011 at 9:56 AM

@ctavares this works great thanks!