Skip to content

Instantiating lazysingleton with different class factories.  #102

Closed
@casvanluijtelaar

Description

@casvanluijtelaar

I have a Service that can be instantiated 2 different ways, by using two factories. however this class gets instantiated I need it to be a lazysingleton.

if I register a singleton like this:

locator.registerLazySingleton<Service>(() => Service());

then how to I instantiate it with a factory constructor later?

Service service = Service.fromJson(data);

needs to be instantiated somewhere in here, to get the singleton reference later on.

GetIt locator = GetIt.instance;
Service service = locator<Service>();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions