OPTIONS PATTERN in ASP.NET Core | Getting Started With ASP.NET Core Series

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • When building applications, it often needs access to different configurations - be it a connection string to a database, ClientId, Secret, external API URLs, tokens, etc. By keeping these values in the application's configuration, we can use different values for different environments. ASP NET Core provides rich support for adding various configuration sources including appsettings.json, environment variables, key vault, and many more.
    In this video, let's learn how to consume these configuration values from the application code you write, using the Options pattern in ASP NET Core. We will see the different interfaces supported by the pattern IOptions, IOptionsSnapshot, and see the differences between them. We can also add validations to ensure configuration values exist and enforce constraints on the values configured.
    🔗Source Code - rahulpnath.vis...
    🔗 Options Pattern - docs.microsoft...
    Additional Watching
    📹How To Use HTTP CLIENT IN ASP NET CORE - • How To Use HTTP CLIENT...
    📹DEPENDENCY INJECTION in ASP.NET Core - • DEPENDENCY INJECTION i...
    📹CONFIGURATION in ASP.NET Core - • CONFIGURATION in ASP.N...
    📹ASP NET Core Series - • ASP.NET Core
    Come say hi! ✋
    🌍 Blog - rahulpnath.com/
    ✉ Subscribe to my Newsletter - www.rahulpnath...
    🐦Twitter - / rahulpnath
    📸Instagram - / rahulpnath
    🎥 Recording Setup and Workflow - www.rahulpnath...
    Video Edited by my wife, Parvathy 😍
    Make sure to SUBSCRIBE to the channel. THANK YOU for helping me grow this channel !!

ความคิดเห็น • 108

  • @ajaysonar1675
    @ajaysonar1675 3 ปีที่แล้ว +15

    Best till date, exactly to the point without any clutter. Thanks !

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thank you Ajay!

  • @payalsharma1413
    @payalsharma1413 3 ปีที่แล้ว +6

    Found this video randomly and after that I watched most of your videos.
    They are very helpful and nicely explained.

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Glad you like them Payal and for letting me know. Do let know if there are any topics you want covered and I will try add more videos.

    • @harishe6069
      @harishe6069 2 ปีที่แล้ว

      Same to same..

  • @kailas141987
    @kailas141987 ปีที่แล้ว

    Best series in .Net core web API. Anyone can learn all concepts by watching this series. It helped me in the interview process. Please give real-world examples along with explanation so we can easily co-relate concepts.

  • @jhlee111
    @jhlee111 2 ปีที่แล้ว +1

    I appreciate your concise way of explaining concepts and when and how it goes wrong in detail. The latter gives me good understanding about why we use it. Thanks!

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      Glad it was helpful! And yes I try to introduce the concepts progressively to make it easier to relate to. Happy you found that particular way useful. Also thank you for supporting me by becoming a member!

  • @bward4126
    @bward4126 2 ปีที่แล้ว +1

    Wow. This was EXACTLY what I needed. Thank you.

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      You're so welcome! Do check out the full series here bit.ly/asp-net-core-series

  • @yuvrajingale526
    @yuvrajingale526 2 หลายเดือนก่อน

    Very informative Video, keep the good work continue🎉

    • @RahulNath
      @RahulNath  2 หลายเดือนก่อน

      Thank you Yuvraj and glad you like it. Hope you are liking the ASP Series bit.ly/asp-net-core-series

  • @iceneno2491
    @iceneno2491 5 หลายเดือนก่อน

    Excellent!

    • @RahulNath
      @RahulNath  5 หลายเดือนก่อน

      Glad you liked it! Hope you are enjoying the series bit.ly/asp-net-core-series

  • @88spaces
    @88spaces 2 ปีที่แล้ว

    This presentation is clear and concise and gets right to the point.

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      Thank you Chris. Do check the full series here th-cam.com/play/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP.html
      I’m sure you’ll like it . Do let know in case you get to watch any 😀

  • @soulfabuk
    @soulfabuk ปีที่แล้ว

    Another great video Rahul, just loved the way you went through separating out variables from the interpolated string before then moving them into the appsettings file. The step-by-step nature makes your videos so much easier to follow than many others!! Keep up the fantastic work.

    • @RahulNath
      @RahulNath  ปีที่แล้ว

      Glad you liked it and thank you for supporting the channel! Hope you are enjoying the full series. Feel free to reach out if you have specific questions or suggestions. 😀

  • @BarbarosYurttagul
    @BarbarosYurttagul ปีที่แล้ว +1

    great

    • @RahulNath
      @RahulNath  ปีที่แล้ว

      Thank you Barbaros!!

  • @mohammedmazin5405
    @mohammedmazin5405 2 ปีที่แล้ว +1

    Super and clear explanatory helped me a lot. Thanks

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว +1

      Thank you!

  • @albertszymanski7177
    @albertszymanski7177 10 หลายเดือนก่อน

    Awesome video. Well-structured and informative. Definitely the best video on this topic out there.

    • @RahulNath
      @RahulNath  10 หลายเดือนก่อน +1

      Glad you enjoyed it! Do check out the full series bit.ly/asp-net-core-series

  • @ChosenHandle
    @ChosenHandle 3 ปีที่แล้ว +1

    Great video. Well structured and informative. Thank you!

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว +1

      Glad you enjoyed it! Do check out the other ones in this series - th-cam.com/play/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP.html

  • @raagasongs
    @raagasongs 3 ปีที่แล้ว

    I personally learn more from your .Net core video's.. It helps to understand the fundamentals of core..

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thank you Rajesh, glad you are finding these helpful. Do let know if you need any other topics covered.

  • @GabrielGoncalves-ez1iv
    @GabrielGoncalves-ez1iv 2 ปีที่แล้ว

    Thanks for this great explanation!!
    #aspnetoptionspattern

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      Glad it was helpful Gabriel! Hope you are enjoying the series bit.ly/asp-net-core-series

  • @vaelinalsorna1649
    @vaelinalsorna1649 2 ปีที่แล้ว

    Good video. Straight to the point and well-spoken.

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว +1

      Thank you Vaelin! Do check out the full series here bit.ly/asp-net-core-series
      I am sure you'll like it!

  • @UPSCCSE-ku7ej
    @UPSCCSE-ku7ej 3 ปีที่แล้ว +1

    Excellent

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thank you! Cheers!

  • @DrGaurangGupta
    @DrGaurangGupta 2 ปีที่แล้ว

    Awesome explanation. Had been struggling to work out the whole concept and you made it crystal clear. Same as your video on dependency inversion principle.
    Love your content!

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว +1

      Glad it helped Gaurang! Do check out the full ASP Series in case you haven't bit.ly/asp-net-core-series

  • @melk48111
    @melk48111 3 ปีที่แล้ว +1

    awesome Rahul

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thank you Melvis! Do checkout my other videos in this Series th-cam.com/play/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP.html. Do let know if there are any specific areas to be covered

  • @SantoshSingh-nw8yy
    @SantoshSingh-nw8yy 2 ปีที่แล้ว

    Good one 👏

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      Thank you! Cheers! Hope you are liking the full series bit.ly/asp-net-core-series

    • @SantoshSingh-nw8yy
      @SantoshSingh-nw8yy 2 ปีที่แล้ว

      @@RahulNath yep subscribed immediately 🙂

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      @@SantoshSingh-nw8yy 🙏

  • @richardekeopara886
    @richardekeopara886 3 ปีที่แล้ว

    Terse and straight to the point. I love your style. Please keep it up!

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thank you Richard! Happy that you like the style and they are helpful.

  • @joshmachine777
    @joshmachine777 ปีที่แล้ว

    Thanks!

    • @RahulNath
      @RahulNath  ปีที่แล้ว

      Thank you Amit and for the super thanks !

  • @velkumars26
    @velkumars26 3 ปีที่แล้ว

    Nice explanation, much informative. Good work bro

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thanks a lot Velkumar!

  • @ashamarias
    @ashamarias 3 ปีที่แล้ว

    Great video Rahul. Well explained!

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Glad you liked it!

  • @suryanarayanbaliarsingh5363
    @suryanarayanbaliarsingh5363 3 ปีที่แล้ว

    Nice explanation..

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Great thanks Suryanarayan. Do check out the other videos in this series th-cam.com/play/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP.html

  • @UPSCCSE-ku7ej
    @UPSCCSE-ku7ej 3 ปีที่แล้ว +1

    Awesome man ...!!

  • @tubeashu
    @tubeashu 3 ปีที่แล้ว +1

    Really liked your video, one of the best with all details.
    How you were able to go into CreateDefaultBuilder, is it possible in VS 2019 ?

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว +1

      Thank you, Ashutosh, and happy that you like them.
      To navigate into functions is not yet available as part of VS - There is an open ticket for that github.com/dotnet/roslyn/issues/24349
      You can use the source.dot.net/ browser, but still, the Rider experience is way better. I mostly use Rider IDE in the video so that I can easily do that within the context of the app. Hope that helps.

  • @ransandu
    @ransandu 3 ปีที่แล้ว

    Thank you ! This helped a lot.

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว +1

      Thanks Ranga!

  • @shreyasjejurkar1233
    @shreyasjejurkar1233 3 ปีที่แล้ว +1

    This is quite great pattern. Nice video as always.
    Rahul any idea who came with up this pattern at start of .net core development?? Any insights you remember? 😁

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thanks, Shreyas, and glad you like the video. I am not sure who came up with the pattern in the first place. (Between I don't work in the .net core team - just in case you thought otherwise 😀)

    • @shreyasjejurkar1233
      @shreyasjejurkar1233 3 ปีที่แล้ว +1

      @@RahulNath but you used to in past correct? When you were at MS!?

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว +1

      @@shreyasjejurkar1233 yeah that’s right, used to 😀

    • @shreyasjejurkar1233
      @shreyasjejurkar1233 3 ปีที่แล้ว +1

      @@RahulNath ahh OK. Ok. No issues! 😇

  • @sarathbaiju6040
    @sarathbaiju6040 2 ปีที่แล้ว +1

    Can you make a video series on SOLID principles?

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว +1

      Great suggestion! I will plan something.

  • @LencoTB
    @LencoTB ปีที่แล้ว

    Your videos are really good. I learned so much. Do you have any examples of how one would implement Options Pattern on Azure Function v4? Function apps use local.settings.json so I am missing an example how I can use the Options Pattern with the new .Net 6 Azure Functions.

  • @meayanaforever
    @meayanaforever 3 ปีที่แล้ว +1

    Second..❤️

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว +1

      fourth 😂

  • @abdullahahmed8468
    @abdullahahmed8468 3 ปีที่แล้ว

    amazing man

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Thank you 😀

  • @klearner666
    @klearner666 2 ปีที่แล้ว

    Can you Do this in Static class.?

  • @LencoTB
    @LencoTB ปีที่แล้ว

    Can't find how to use ValidateDataAnnotations for Azure Functions v4

  • @staker4
    @staker4 3 ปีที่แล้ว

    👍

  • @piyalibasak6886
    @piyalibasak6886 ปีที่แล้ว

    please explain a video of single tone scoped in distributed architecture

    • @RahulNath
      @RahulNath  ปีที่แล้ว

      Can you explain a bit more on what you are looking for ? I’ve a video on Dependency Injection and lifetime scopes including Singleton in it th-cam.com/video/YR6HkvNBpX4/w-d-xo.html
      What specific are you looking for with distributed architecture?

    • @piyalibasak6886
      @piyalibasak6886 ปีที่แล้ว +1

      @@RahulNath I want a video where you can explain me about why we should use singletone design pattern.Generally I have seen your video of DI already.but I want to know specific real scenario where we should use single tone as well as transient and scope in .net core with real project base scenario.and if you make one video where we should use normal singletone class not specific to .net core app,in general .(I know the logic of singletone,scope and transient but I just want there use of real project based scenario from you) if you can make video on this with good information it will be really helpfull for me.

    • @RahulNath
      @RahulNath  ปีที่แล้ว

      Thank you for your suggestion Piyali! I will add this to my list and see if I can do one soon.

  • @rohan4rich
    @rohan4rich 3 ปีที่แล้ว +1

    What is the difference between services.AddOptions and services.ConfigureOptions ?

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      These two articles might help understand it a bit better -
      andrewlock.net/the-dangers-and-gotchas-of-using-scoped-services-when-configuring-options-in-asp-net-core/
      andrewlock.net/simplifying-dependency-injection-for-iconfigureoptions-with-the-configureoptions-helper/
      Let know if you have further questions and happy to do a follow up video on this.

    • @rohan4rich
      @rohan4rich 3 ปีที่แล้ว

      @@RahulNath Thank you Rahul I will surly follow these articles.

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      @@rohan4rich Sure feel free to reach out in case you have more questions Rohan.

  • @kalpeshblue2
    @kalpeshblue2 3 ปีที่แล้ว +1

    first :)

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว +1

      third 😀

  • @VindicatorMorty
    @VindicatorMorty 3 ปีที่แล้ว

    How can i add a service with a custom created IOptions? Like services.AddScoped(options => options.Operation = "string" );

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      Should be possible using the Factory overrride - docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.servicecollectionserviceextensions.addscoped?view=dotnet-plat-ext-5.0&WT.mc_id=AZ-MVP-5003875
      Did you get a chance to try that? Let know if you are facing any issues.

  • @henrrypires794
    @henrrypires794 ปีที่แล้ว

    I don't understand why do you use IOptions, what's the point of that interface?

    • @RahulNath
      @RahulNath  ปีที่แล้ว

      It streamlines the way you can inject configuration objects into your classes, automatically refresh when values change (based on how it is set up), etc. An alternative would be custom writing all of that. What are you trying to use it for?

    • @henrrypires794
      @henrrypires794 ปีที่แล้ว +1

      @@RahulNath i was woudering why not inject the class with the configuration values and use this IOptions interface. but now i understand. Thanks

  • @melk48111
    @melk48111 3 ปีที่แล้ว

    which editor are you using?

    • @RahulNath
      @RahulNath  3 ปีที่แล้ว

      I am using Jetbrains Rider - www.jetbrains.com/rider/download/#section=windows
      You can also check out their Early Access Program which provides free access www.jetbrains.com/resources/eap/

  • @expertreviews1112
    @expertreviews1112 2 ปีที่แล้ว

    Question, can Options pattern be used to pass something other than config... what if I want to pass CustomerName to a Customer class? Can I use options pattern to pass Customer name and/or other info ?? Or maybe I want to pass a GUID to a class ??? thnx in advance

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      It’s not restricted to config. You could pass anything. Curious why you want to pass customer name though and how you intend to get the name . If it’s in context of request why not keep it as a function parameter ?

    • @expertreviews1112
      @expertreviews1112 2 ปีที่แล้ว

      @@RahulNath thnx... without going into too much detail, I had a scenario where my Webhook service was receiving a token. The controller would pass this to a handler service. This handler service accepts a dependency which also requires this token to be available to all its members... I tried the options pattern but somehow couldn't make it work... Token as function parameter meant if I had 10 functions, I'd have a token arg in each of them and I wanted to avoid this...thnx in advance

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      @@expertreviews1112 you could have a “ContextService” injected in and have a set on it to set the token which you can call at the beginning of your handler. Easiest I can think of achieving this

    • @expertreviews1112
      @expertreviews1112 2 ปีที่แล้ว +1

      @@RahulNath Interesting! Many thnx, I'll give it a shot!!

    • @RahulNath
      @RahulNath  2 ปีที่แล้ว

      @@expertreviews1112 Do let me know how that goes 👍