Video není dostupné.
Omlouváme se.

Made EASY - WPF Dependency Injection with IServiceCollection

Sdílet
Vložit
  • čas přidán 23. 06. 2024
  • Dependency injection is a core part of any modern C# application -- and WPF apps are no different!
    In this video, I'll walk you through how we can transform a simple WPF application to take advantage of dependency injection using IServiceCollection.
    And you know that fun MVVM pattern that gets used heavily with WPF?
    Rest assured! We can inject our View Models into our Views with IServiceCollection and clean things up nicely!
    ----
    🔑 Membership & Subscriptions:
    - 📨 Weekly Newsletter: weekly.devleader.ca
    - 🏘️ Private Discord Community: / discord
    - 📽️ CZcams Membership: / @devleader
    🧠 Courses:
    - All Courses: www.devleader.ca/courses
    - Getting Started with C#: dometrain.com/course/getting-...
    - Deep dive C#: dometrain.com/course/deep-div...
    - C# Zero to Hero BUNDLE: dometrain.com/bundle/from-zer...
    - Refactoring For C# Devs: dometrain.com/course/from-zer...
    - [FREE] Intro to Software Development: • [FREE MINI COURSE] - I...
    🗣️ Social Media & Links:
    - All My Links: linktr.ee/devleader
    - Blog: www.devleader.ca/
    - TikTok: / devleader
    - LinkedIn: / nickcosentino
    - Threads: threads.net/@dev.leader
    - Twitter: / devleaderca
    - Facebook: / devleaderca
    - Instagram: / dev.leader
    - GitHub: github.com/ncosentino/
    - Twitch: / devleaderca
    - CZcams: / @devleader
    ❤️ Affiliations & Products/Services That I Love:
    - VPS hosting from RackNerd: my.racknerd.com/aff.php?aff=9013
    - VPS hosting from Contabo: www.jdoqocy.com/click-1010286...
    - My newsletter platform ConverKit: convertkit.com/?lmref=c5X7KQ
    - My newsletter referral system SparkLoop: dash.sparkloop.app/signup?aff...
    - My AI shorts helper Opus Clip: opus.pro/?via=2f9e97
    - I try to help answer questions at Quora: www.quora.com/quoraplus?ch=10...
    - My favorite computer parts store Newegg: click.linksynergy.com/fs-bin/...
    - My favorite supplement store Bulk Supplements: glnk.io/63qn/devleader
    ----
    #dotnet #csharp #wpf #frontend

Komentáře • 13

  • @DevLeader
    @DevLeader  Před měsícem

    💡 Learn how to program in C#:
    - dometrain.com/course/getting-started-csharp?affcode=1115529_nl-teyzg
    🧠Deep dive on C#:
    - dometrain.com/course/deep-dive-csharp?affcode=1115529_nl-teyzg
    🎁Zero to Hero C# Bundle:
    - dometrain.com/bundle/from-zero-to-hero-csharp/?affcode=1115529_nl-teyzg
    💪 Skill up your refactoring:
    - dometrain.com/course/from-zero-to-hero-refactoring-for-csharp-developers?affcode=1115529_nl-teyzg
    ✉ Subscribe to my free software engineering newsletter:
    - subscribe.devleader.ca

  • @fuyuzero
    @fuyuzero Před měsícem +2

    I really appreciate your content on WPF. I feel that it gets passed over for browser-focused tutorials but is really good skill to know more about. Thanks!

    • @DevLeader
      @DevLeader  Před měsícem +1

      I'll be covering more on it 🙂 I spent so long working with it and wish I would have made more videos over the last decade lol

    • @pkop4
      @pkop4 Před měsícem +1

      @@DevLeader I'm just learning WPF and find it to be a great framework, and it's nice to build native apps instead of web apps. Thanks for your help and content.

  • @golibjontuxtamatov5808
    @golibjontuxtamatov5808 Před 19 dny +1

    hi there, how can I inject a service in usercontrol, thanks for answering

    • @DevLeader
      @DevLeader  Před 19 dny

      I try to cover that in an earlier video 🙂
      czcams.com/video/AoQnI5St1Qg/video.html

  • @williamliu8985
    @williamliu8985 Před měsícem

    Hi Nick, how do you get service from IOC in converter. A step further, if the converter is from a sub project.

    • @DevLeader
      @DevLeader  Před měsícem

      I'll need to do a follow up video on this. You won't be able to make that work unless you can register the converter onto your container though. If you *can* do that, it should be fine.
      In this context, you mean a value converter, right? Something you might use for binding?

    • @williamliu8985
      @williamliu8985 Před měsícem +1

      @@DevLeader Correct, I just mean value converter. I would like to put logic into service which is commonly being unit tested, then invoke the service from value converter. It`s not easy to get service in value converter, or the value converter is in a sub project.

    • @DevLeader
      @DevLeader  Před měsícem

      @@williamliu8985 let me add this one to the list - will try to get a video out. Should be very doable but the thing is we're probably fighting WPF here. If you put your binding with converter into XAML, then you don't own the lifetime creation of the converter via dependency injection. So we need to work around that 🙂

    • @trebiax7960
      @trebiax7960 Před měsícem +1

      @@DevLeaderyeah that probably requires some tricks, one of them, we would require some static IServiceProvider in the Value converter class to resolve dependencies not via constructor

    • @DevLeader
      @DevLeader  Před měsícem +2

      @@trebiax7960 yup - probably a few options but none I'm in love with. I've used them all before though:
      - You bite the bullet and slap a static property for doing service location onto your converter. This is the easiest and also least flexible especially when you get into testing.
      - We bypass XAML and wire these things up after resolving via constructor dependency injection (or similar). Way nicer IMO but you're immediately fighting against how this stuff was designed to be used lol