{"id":34591,"date":"2021-12-31T20:25:39","date_gmt":"2022-01-01T01:25:39","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=34591"},"modified":"2022-05-05T13:45:46","modified_gmt":"2022-05-05T17:45:46","slug":"lightweight-dependency-injection-using-async-functions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/12\/31\/lightweight-dependency-injection-using-async-functions\/","title":{"rendered":"Lightweight Dependency Injection Using Async Functions"},"content":{"rendered":"<p><a href=\"https:\/\/www.swiftbysundell.com\/articles\/dependency-injection-and-unit-testing-using-async-await\/\">John Sundell<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.swiftbysundell.com\/articles\/dependency-injection-and-unit-testing-using-async-await\/\">\n<p>What if we could actually make our code fully testable in a way that doesn&rsquo;t require us to introduce any new protocols, mocking types, or complicated abstractions? Let&rsquo;s explore how we could make use of Swift&rsquo;s new <code>async\/await<\/code> capabilities to make that happen.<\/p>\n<p>[&#8230;]<\/p>\n<p>One thing that&rsquo;s very neat about the above pattern is that it still lets us keep using our existing <code>Networking<\/code> and <code>ProductLoader<\/code> code just like before &mdash; all that we have to do is to call that code within the <code>reloading<\/code> function\/closure that we pass into our <code>ProductViewModel<\/code> when creating it[&#8230;]<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/09\/21\/swift-5-5-released\/\">Swift 5.5 Released<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>John Sundell: What if we could actually make our code fully testable in a way that doesn&rsquo;t require us to introduce any new protocols, mocking types, or complicated abstractions? Let&rsquo;s explore how we could make use of Swift&rsquo;s new async\/await capabilities to make that happen. [&#8230;] One thing that&rsquo;s very neat about the above pattern [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2022-01-01T01:25:42Z","apple_news_api_id":"a69c5322-e74f-4f86-9744-a37dcf12171d","apple_news_api_modified_at":"2022-01-01T01:25:42Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AppxTIudPT4aXRKN9zxIXHQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[27,71,2200,901,268],"class_list":["post-34591","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-craft","tag-programming","tag-swift-concurrency","tag-swift-programming-language","tag-testing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=34591"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34591\/revisions"}],"predecessor-version":[{"id":34592,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34591\/revisions\/34592"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=34591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=34591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=34591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}