Does the MVVM Light SimpleIoC support singletons?

前端 未结 2 1623
执笔经年
执笔经年 2020-12-19 02:30

I\'m using SterlingDB in my current Windows Phone project, and I would like to be able to resolve the Sterling database from various places in my application using the new S

2条回答
  •  难免孤独
    2020-12-19 02:44

    SimpleIoc returns instances based on a key that you pass to it. If you call GetInstance() without a key, you will always get the default instance of your object. The instance is only created when you call GetInstance the first time (lazy creation). If you call GetInstance with a key, I look up if this named instance already exists in the registry. If it doesn't yet, I create it and then I return it. If there is an instance with that key already, I just return it.

    In the alpha version (BL16 MIX edition), there is a bug that caused Register to create the instance too early, when a key was used. This bug is fixes in V4 beta1 which I will publish this week.

    So as you see you will get the same instance from SimpleIoc if you always use the same key (or simply the default instance if you don't use a key at all).

    Does it make sense? Laurent

提交回复
热议问题