1

如果我将 Typhoon 与 java 中常见的 IOC 容器之一进行比较,我在文档中找不到两个重要的特性。

如何注释@autowired?如何注释@Scope?尤其是 SCOPE_SINGLETON 和 SCOPE_PROTOTYPE 之间的区别。

更多关于这里的春天:http: //docs.spring.io/spring/docs/4.0.0.RELEASE/spring-framework-reference/html/beans.html#beans-standard-annotations

4

1 回答 1

0

Typhoon supports the prototype and singleton scopes along with two other scopes designed specifically for mobile and desktop applications.

In a server-side application, the server may be supporting any of the application's use-cases at a given time. Therefore it makes sense for those components to have the singleton scope. In a mobile application, while there are background services its more common to service one use case at a time. And there are memory, CPU and batter constraints.

Therefore the default scope with Typhoon is TyphoonScopeObjectGraph, which means that references to other components while resolving eg a top-level controller will be shared. In this way an object graph can be loaded up and then disposed of when done.

There's also the following:

Auto-wiring macros vs native style assembly:

Unfortunately, Objective-C has only limited run-time support for "annotations" using macros. So the option was to use either a compile-time pre-processor, which has some drawbacks, or to work around the limitations and force it in using a quirky style. We decided that its best (for now) to use Macros only for simple convention-over-configuration cases.

For more control we strongly recommend using the native style of assembly. This allows the following:

  • Modularize an application's configuration, so that the architecture tells a story.
  • IDE code-completion and refactoring works without any additional plugins.
  • Components can be resolved at runtime using the assembly interface, using Objective-C's AOP-like dynamism.

To set the scope using the native style:

- (id)rootController
{
    return [TyphoonDefinition withClass:[RootViewController class] 
        configuration:^(TyphoonDefinition* definition)
    {
        definition.scope = TyphoonScopeSingleton;
    }];
} 
于 2014-05-23T08:16:23.253 回答