The SIMPLEIOC of Mvvmlight learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.