Tuesday, February 15, 2011

OxenIoC: IoC container for Objective C.Part 2

We have improved our OxenIoC container. We have fixed one bug, the only one that we detected, and we have added some new features that help to write less code to define objects into container and their dependencies.

The main idea is to use a mechanism like java annotations or c# attributes. We developed some preprocessors macros for this.

The preprocessors macros defined are:
  • IoCName(name): Defines a name for the object. If you don't use this "annotation" then the object will be named like the class name.
  • IoCLazy: Defines if it is Lazy.
  • IoCSingleton: Defines if the object is Singleton.
  • IoCInject(property, objectName): Inject the object whose name is "objectName" into the property named "property".
Example:
#import "ServiceExecutorImpl3.h"
#import "IoCContainer.h"
@implementation ServiceExecutorImpl3
@synthesize service;
IoCName(ServiceExecutor3)
IoCLazy IoCSingleton
IoCInject(service, theService)
- (void) executeService {
     [service execute];
}
@end 
This example defines an object named ServiceExecutor3, lazy, singleton and injects into property "service" the object named "theService".

For getting the instance of this class we just call the getObject method

id executor = [container getObject:@"ServiceExecutor3"];

So, this is a third way to defines objects into container. The others two are by instancing a ObjectDefinition object and by xml.

To get the code click here

Part1 of this post click here


4 comments:

  1. Your code formatting is broken

    ReplyDelete
  2. Thanks, we didn't realized about that. We're fixing it.

    ReplyDelete
  3. your post is nice, informative & helpful for everyone. thanks for sharing.

    macromedia dreamweaver

    ReplyDelete