Skip to content

Registration

Danil Kovalev edited this page Jul 8, 2019 · 2 revisions

For now, you can pass only 3 arguments when registering your service. Lets figure it out:

func register<T: Containerable.Object>(registrationType: ContainerObject.RegistrationType = .automatic, name: String? = nil, _ registration: @escaping (() -> T))
  1. registrationType - is enum with two cases
enum RegistrationType {
    case manual
    case automatic
}

If you'll select the automatic case, all your properties of class you registering, will be resolved automatically. So, if you'll select the manual case, you will be able to manually select how to resolve any of your properties. And no one of them will be resolved automatically.

  1. name - It's just a String

This parameter specifies your services. For example, if you registered two classes with same type, framework have to know which one on them should be resolved. And this argument helps to figure it out. So, if you will register two objects with same type, SwiftInjector will return the first registered object.

  1. registration - Closure with return type

In this closure you have to return object you want to register. It will be putted in RAM memmory only after first resolve, not after registration.

Clone this wiki locally