EnesKaraosman / Swinjector

Simple dependency injection package inspired by get_it Flutter package

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swinjector

codecov

TODO

  • Easify registering and resolving dependency syntax?
  • Support registering multiple instance of the same type?
  • Add code documentation
  • Add unit test execution github action
  • Integrate code coverage app (codecov)
    • Unit test code coverage %100

Register dependencies

// Lazy singleton is created when you access it
GetIt.I.registerLazySingleton(TestProtocol.self) { TestClass() }

// Singleton is already created by you
GetIt.I.registerSingleton(TestProtocol.self, instance: TestClass())

// New instance is created every time you access it
GetIt.I.registerFactory(TestProtocol.self) { TestClass() }

Access dependencies

if let instance = GetIt.I.resolve(TestProtocol.self) {}

// More swifty syntax
if let instance = GetIt.I(TestProtocol.self) {}

// Access by annotation
@Injected(TestProtocol.self) var instance
instance().foo()

Check if dependency is registered & unregister

let isRegistered = GetIt.I.isRegistered(TestProtocol.self)

GetIt.I.unregister(TestProtocol.self)

About

Simple dependency injection package inspired by get_it Flutter package


Languages

Language:Swift 100.0%