Swinject: Singleton service ?

Created on 29 Aug 2015  路  1Comment  路  Source: Swinject/Swinject

Can we have a singleton from the container? I have a use case that I need always the same service reference from the container. Can I do this ?

Thanks

question

Most helpful comment

ObjectScope.Container is the singleton setting for Swinject.

container.register(AnimalType.self) { _ in Cat() }
    .inObjectScope(.Container)

Refer to the following document for the details of the object scopes:
https://github.com/Swinject/Swinject/blob/master/Documentation/ObjectScopes.md

Thank you for trying Swinject and adding a star.

>All comments

ObjectScope.Container is the singleton setting for Swinject.

container.register(AnimalType.self) { _ in Cat() }
    .inObjectScope(.Container)

Refer to the following document for the details of the object scopes:
https://github.com/Swinject/Swinject/blob/master/Documentation/ObjectScopes.md

Thank you for trying Swinject and adding a star.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mijail picture Mijail  路  6Comments

irace picture irace  路  5Comments

sialcasa picture sialcasa  路  5Comments

drekka picture drekka  路  7Comments

diwengrum picture diwengrum  路  5Comments