Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement <TyphoonDetachableComponentFactoryPostProcessor> #171

Closed
jasperblues opened this issue Feb 7, 2014 · 8 comments
Closed

Implement <TyphoonDetachableComponentFactoryPostProcessor> #171

jasperblues opened this issue Feb 7, 2014 · 8 comments

Comments

@jasperblues
Copy link
Member

NSInvalidArgumentException "Key 'synchronizeOperation$$$patcher' is already registered.” raised at creating object by factory after calling TyphoonComponentFactory’s unload method.

@rizumita
Copy link

rizumita commented Feb 7, 2014

This is sample code.

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    TyphoonComponentFactory *factory = [TyphoonBlockComponentFactory factoryWithAssemblies:@[[ComponentsAssembly assembly]]];
    TyphoonPatcher *patcher = [TyphoonPatcher new];
    [patcher patchDefinitionWithKey:@"dataManager" withObject:^id{
        return [DataManager new];
    }];
    [factory attachPostProcessor:patcher];
    [factory makeDefault];
}

- (void)testExample
{
    DataManager *manager = [[TyphoonComponentFactory defaultFactory] componentForKey:@"dataManager"];
    [(TyphoonComponentFactory *)[TyphoonComponentFactory defaultFactory] unload];
    manager = [[TyphoonComponentFactory defaultFactory] componentForKey:@"dataManager"];

    XCTAssertTrue(YES);
}

@jasperblues
Copy link
Member Author

To implement [patcher detach] we need to implement on

  • TyphoonInitializer
  • TyphoonDefinition
  • All sub-classes of TyphoonAbstractInjectedParameter (initializers)
  • All sub-classes of TyphoonAbstractInjectedProperty

. . . so that we can save the old pre-patched definitions.

@jasperblues
Copy link
Member Author

Changing from bug to enhancement. Calling unload on TyphoonComponentFactory as done in the example will unload the singletons, however once a post-processor has been attached the definitions are permanently mutated. . . . so what is really required is a

<TyphoonDetachableComponentFactoryPostProcessor>

@jasperblues
Copy link
Member Author

Have implemented the copy methods, now need to create and make the patcher conform to

@jasperblues
Copy link
Member Author

@rizumita We've been very busy! Will close this issue ASAP. (perhaps not until after Friday).

@jasperblues
Copy link
Member Author

@rizumita This has now been implemented. A patcher can be removed by calling:

[patcher detach];

To test use:

pod 'Typhoon', :head

(we'll push a new version after we receive your 👍 )

  • Currently a patcher can only be removed if it is the last TyphoonComponentFactoryPostProcessor to be added.
  • I remember part of your issue was related to calling [factory makeDefault] again. In version 2.0 we recommend to avoid using defaultFactory globals, however if you do wish to use them, we have at least removed the restriction where it could only be set once. . . this may also help.
  • Instead of using defaultFactory we recommend injecting the factory, as described here: http://bit.ly/1s4uJsM

@rizumita
Copy link

rizumita commented May 4, 2014

I don't use the 'detach' method in test code and the following error log was outputted.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Key 'logger$$$patcher' is already registered.'

Then I use the 'detach' method and I got no error.
I think the 'detach' method of new version runs correctly.

Thank you for the enhancement!

@jasperblues
Copy link
Member Author

:) pushed to CocoaPods as 2.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants