memrise ios android,GitHub - Memrise/DependencyContainer-iOS

DEPRECATED

This repository is archived because the code was moved as a local pod to the main iOS app https://github.com/Memrise/Memrise-iOS.

MRDependencyContainer

Simple Dependency Container.

Why?

One of problems that we struggled with was the lack of control over modules initialisation. For example a service initialised in one part of the application required some dependency that was created in the another part. Also both services must be initialised after service X was initialised.

In MRDependencyContainer you define a factory (DependencyAssembler) which creates the dependency. Then when the container is setup it uses Assemblers to build these dependencies. This way you have one place to register and create services and control when in the application lifecycle they are created.

Features

Very small and simple.

Supports Obj-C

Specialised classes to define a process of creating dependency ('DependencyAssembler').

You decide when, in the application life cycle, services are created.

Installing

CocoaPods

pod 'MRDependencyContainer'

Usage

Swift

A services registration and the container setup.

import MRDependencyContainer

let container = DependencyContainer()

let assembler = DefaultDependencyAssembler(type: TestService.self) { container -> TestService in

return TestService()

})

container.register(assembler)

container.setup()

Resolving dependencies

let service = container.resolve() as TestService?

ObjC

@import MRDependencyContainer;

DependencyContainer container = [[DependencyContainer alloc] init];

DefaultLegacyDependencyAssembler *assembler = [DefaultLegacyDependencyAssembler createWithType:[TestService class] andBlock:^ id (DependencyContainer *container){

return TestService();

}];

[container register:assembler];

[container setup];

Resolving dependencies

TestService *service = [container resolveByClass:TestService.class];

Limitations

Resolving dependencies by a protocol is not supported in Obj-C

You cannot register a new assembler after container setup.

License

MRDependencyContainer is available under the MIT license. See LICENSE for more information.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值