2 * Copyright 2018 Google
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #import <Foundation/Foundation.h>
20 @class FIRComponentContainer;
22 NS_ASSUME_NONNULL_BEGIN
24 /// Provides a system to clean up cached instances returned from the component system.
25 NS_SWIFT_NAME(ComponentLifecycleMaintainer)
26 @protocol FIRComponentLifecycleMaintainer
27 /// The associated app will be deleted, clean up any resources as they are about to be deallocated.
28 - (void)appWillBeDeleted:(FIRApp *)app;
31 typedef _Nullable id (^FIRComponentCreationBlock)(FIRComponentContainer *container,
33 NS_SWIFT_NAME(ComponentCreationBlock);
37 /// Describes the timing of instantiation. Note: new components should default to lazy unless there
38 /// is a strong reason to be eager.
39 typedef NS_ENUM(NSInteger, FIRInstantiationTiming) {
40 FIRInstantiationTimingLazy,
41 FIRInstantiationTimingAlwaysEager,
42 FIRInstantiationTimingEagerInDefaultApp
43 } NS_SWIFT_NAME(InstantiationTiming);
45 /// A component that can be used from other Firebase SDKs.
46 NS_SWIFT_NAME(Component)
47 @interface FIRComponent : NSObject
49 /// The protocol describing functionality provided from the Component.
50 @property(nonatomic, strong, readonly) Protocol *protocol;
52 /// The timing of instantiation.
53 @property(nonatomic, readonly) FIRInstantiationTiming instantiationTiming;
55 /// An array of dependencies for the component.
56 @property(nonatomic, copy, readonly) NSArray<FIRDependency *> *dependencies;
58 /// A block to instantiate an instance of the component with the appropriate dependencies.
59 @property(nonatomic, copy, readonly) FIRComponentCreationBlock creationBlock;
61 // There's an issue with long NS_SWIFT_NAMES that causes compilation to fail, disable clang-format
62 // for the next two methods.
65 /// Creates a component with no dependencies that will be lazily initialized.
66 + (instancetype)componentWithProtocol:(Protocol *)protocol
67 creationBlock:(FIRComponentCreationBlock)creationBlock
68 NS_SWIFT_NAME(init(_:creationBlock:));
70 /// Creates a component to be registered with the component container.
72 /// @param protocol - The protocol describing functionality provided by the component.
73 /// @param instantiationTiming - When the component should be initialized. Use .lazy unless there's
74 /// a good reason to be instantiated earlier.
75 /// @param dependencies - Any dependencies the `implementingClass` has, optional or required.
76 /// @param creationBlock - A block to instantiate the component with a container, and if
77 /// @return A component that can be registered with the component container.
78 + (instancetype)componentWithProtocol:(Protocol *)protocol
79 instantiationTiming:(FIRInstantiationTiming)instantiationTiming
80 dependencies:(NSArray<FIRDependency *> *)dependencies
81 creationBlock:(FIRComponentCreationBlock)creationBlock
82 NS_SWIFT_NAME(init(_:instantiationTiming:dependencies:creationBlock:));
87 - (instancetype)init NS_UNAVAILABLE;