I'm trying to patch an Assembly from within the assembly (or an different assembly).
The method described in https://github.com/appsquickly/Typhoon/wiki/Integration-Testing#patching-out-a-component is working perfectly, but it's a bit complicated when reusing the same assemblies in multiply apps, while trying to patch only certain aspects. I'know I can modularize my assembly structure to get this thing done, but I'd repeat myself, for all the unpatched definitions. Subclassing might be another option, but I'd need to subclass a lot of definitions, only to change one aspect.
In short: I'm trying to move this into my assembly:
MiddleAgesAssembly* assembly = [[MiddleAgesAssembly assembly] activate];
TyphoonPatcher* patcher = [[TyphoonPatcher alloc] init];
[patcher patchDefinitionWithSelector:@selector(knight) withObject:^id{
return [assembly anotherKnight];
}];
[assembly attachPostProcessor:patcher];
One possible solution (I haven't tried yet) might be to create my own implementation of TyphoonDefinitionPostProcessor. But before loosing myself in the implementation, I wanted to ask, if anyone has an elegant solution for the general problem.
While more workarounds are appreciated, I'd rather like to know, if it's possible to patch the assembly from within another assembly.
Thanks, Martin
Its not possible to patch an assembly from another assembly - this is not currently a supported feature.
However if you want to create reusable assemblies and just patch out certain parts, you can create a sub-class that overrides just the parts that you want to customer.
Let's say you have a top-level assembly with a collaborating assembly as follows:
@interface MiddleAgesAssembly : TyphoonAssembly
@property(strong, nonatomic, readonly) QuestProvider *questProvider;
@end
When you activate an assembly you can specify any assemblies that will override the base assembly as follows:
[MyAssembly new] activateWithCollaboratingAssemblies:@[HolyGrailQuestProvider new]];
//HolyGrailQuestProvider will act in place of the base quest provider