AOP in CAB ... what do you think?

Topics: CAB & Smart Client Software Factory
Jul 20, 2005 at 12:14 PM
originally posted by: jwalklin

I've extended the CAB component model with a new service interface for creating component instances:

public interface IComponentFactoryService
object CreateInstance(Type type);
T CreateInstance<T>() where T : new();

I modified CompositeContainer to provide a default implementation of this service.

Armed with my new service, I then extended DependencyInjectionContainer with a class named InjectionContainer. The only thing this container does is add an AspectInjectionComponentFactory (implementing IComponentFactoryService). This factory proxies newly created objects, injecting aspects using interceptors and mixins (I'm using Castle Project).

This has served me well to integrate services that are orthoganal to my business domain (e.g. undo/redo support, security). The injected aspects are, in turn, Sited so their dependencies can be injected (e.g. an authentication service).

Just wanted a sanity check for my approach and to see if anyone has tried anything different.

Thanks, Jim
Aug 13, 2005 at 11:48 AM
originally posted by: EdJez

I think this is very consistent with my point of view.

Things I would make sure OK are:
- when you add an object to the container, make sure it's the 'proxy' reference!
- take care of the scope of reuse of the intercepting filters themselves (are they used only for one intercepted instance, many, even avross workitems? Again I'm not familiar with sandcastle but have done this general pattern a lot and when I was thinking about introducing it in CAB, it became evident that the intercepting filters would want to use services from the current workitem (the conceptual 'context'). For example, if you add to the interception pipeline an Auditing filter for an object, you want to make sure the Auditing filter is useing the rignt IAuditingService implmentation from the current workitem ('container')

Haven't used Castle personally, but I have worked a lot with AOSD concepts & people (Gregor K, Christa) myself, and I think the merger of compositon styles (injection, aspect-orientation, dynamic extensions of the type system, etc) is overall a good trend.