All Projects → viniciusaro → Swiftresolver

viniciusaro / Swiftresolver

Licence: mit
Dependency injection framework for Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swiftresolver

Scabbard
🗡 A tool to visualize Dagger 2 dependency graphs
Stars: ✭ 615 (+2265.38%)
Mutual labels:  dependency-injection
Di
DI: C++14 Dependency Injection Library
Stars: ✭ 756 (+2807.69%)
Mutual labels:  dependency-injection
Inject.dart
Compile-time dependency injection for Dart and Flutter
Stars: ✭ 833 (+3103.85%)
Mutual labels:  dependency-injection
Di
💎 Flexible, compiled and full-featured Dependency Injection Container with perfectly usable autowiring and support for all new PHP 7 features.
Stars: ✭ 645 (+2380.77%)
Mutual labels:  dependency-injection
Opulence
A simple, secure, and scalable PHP application framework
Stars: ✭ 723 (+2680.77%)
Mutual labels:  dependency-injection
Shiftscheduler
A boilerplate ASP.NET Core project, including a sample employee shift scheduler app
Stars: ✭ 5 (-80.77%)
Mutual labels:  dependency-injection
Dryioc
DryIoc is fast, small, full-featured IoC Container for .NET
Stars: ✭ 555 (+2034.62%)
Mutual labels:  dependency-injection
Koa Typeorm Starter
Starter project for using koa with TS and TypeORM
Stars: ✭ 23 (-11.54%)
Mutual labels:  dependency-injection
Go Spring
基于 IoC 的 Go 后端一站式开发框架 🚀
Stars: ✭ 744 (+2761.54%)
Mutual labels:  dependency-injection
Marvelheroes
❤️ A sample Marvel heroes application based on MVVM (ViewModel, Coroutines, LiveData, Room, Repository, Koin) architecture.
Stars: ✭ 826 (+3076.92%)
Mutual labels:  dependency-injection
Injector
Python dependency injection framework, inspired by Guice
Stars: ✭ 651 (+2403.85%)
Mutual labels:  dependency-injection
Apk Dependency Graph
Android class dependency visualizer. This tool helps to visualize the current state of the project.
Stars: ✭ 675 (+2496.15%)
Mutual labels:  dependency-injection
Koin
Koin - a pragmatic lightweight dependency injection framework for Kotlin
Stars: ✭ 7,142 (+27369.23%)
Mutual labels:  dependency-injection
Wire
Compile-time Dependency Injection for Go
Stars: ✭ 7,091 (+27173.08%)
Mutual labels:  dependency-injection
Inherited builder
🤖Autogenerated state management and dependency injection with inherited widgets
Stars: ✭ 17 (-34.62%)
Mutual labels:  dependency-injection
Frint
Modular JavaScript framework for building scalable and reactive applications
Stars: ✭ 608 (+2238.46%)
Mutual labels:  dependency-injection
Droidparts
Stars: ✭ 785 (+2919.23%)
Mutual labels:  dependency-injection
Kodein Mvvm
Example app using Kodein for dependency injection with MVVM and Architecture Components
Stars: ✭ 26 (+0%)
Mutual labels:  dependency-injection
Grpc
A proof of concept for a way to implement gRPC services in a code first way using C# and .NET Core.
Stars: ✭ 17 (-34.62%)
Mutual labels:  dependency-injection
Di
Dependency Injection and IoC framework for PHP
Stars: ✭ 5 (-80.77%)
Mutual labels:  dependency-injection

SwiftResolver

Dependency injection framework for Swift.

Usage

container.register { MyService() as Service }
...
let service: Service = container.resolve()

You can find more detailed use cases in the wiki page

Instalation

pod 'SwiftResolver'

Multiple Implementations of same Protocol

You can register multiple implementations of the same protocol in the same container. Later, when resolving, the specific type of the implementation can be passed as parameter to obtain the correct implementation type.

container.register(MyService.init).as(ServiceProtocol.self)
container.register(OtherService.init).as(ServiceProtocol.self)
...
let service: ServiceProtocol = container.resolve(MyService.self) // instance of MyService is returned here

Multiple Configurations

You can register multiple implementations of the same object with different configurations. Later, when resolving, an identifier of the implementation can be passed as parameter to obtain the instance with the correct configuration.

enum MyServices: String {
    case mock
    case live
}

container.register { MyService(requestProvider: liveRequestProvider) as Service }.tag(MyServices.live)
container.register { MyService(requestProvider: mockRequestProvider) as Service }.tag(MyServices.mock)
...
let service: Service = container.resolve(MyServices.live)

Thread Safety

SwiftResolver is thread safe. This means you can register/resolve in different threads.

However, this is not a good practice since resolving instances that are not registered yet results in a fatalError.

It is recommended to use an AppContainer as described in the wiki page for a one time registration process.

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].