1 Simpleioc is a simple dependency injection container;2 3 Example: Mainviewmodel needs to use a service or class, assuming I need the person class4 5 first, the implemented service is registered to the SIMPLEIOC,6Simpleioc.default.register<person> (() =NewPerson ());7 and then register the Mainviewmodel with the SIMPLEIOC,8Simpleioc.default.register<mainviewmodel>();9 Ten OneYou can get through servicelocator.current.getinstance<mainviewmodel>.() to obtain an instance of a Mainviewmodel,
And the matching object is found in SIMPLEIOC according to the construction parameters of Mainviewmodel, then it can be used; A - Public classViewmodellocator - { the StaticViewmodellocator () - { -Servicelocator.setlocatorprovider (() = Simpleioc.default);//Set the default SIMPLEIOC -Simpleioc.default.register<person> (() =NewPerson ());//register your class with SIMPLEIOC + -Simpleioc.default.register<mainviewmodel> ();//Register the Mainviewmodel with the SIMPLEIOC, too . + } A PublicMainviewmodel Main at { - Get - { - returnServicelocator.current.getinstance<mainviewmodel> ();//get an instance of Mainviewmodel - } - } in } - to + PublicMainviewmodel (person data)///Mainviewmodel construction parameters, matching the person class - { theWelcometitle =data. Name; *}
The SIMPLEIOC of Mvvmlight learning