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

Sdílet
Vložit
  • čas přidán 4. 11. 2020
  • 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.visualstudio.com/D...
    🔗 Options Pattern - docs.microsoft.com/en-us/aspn...
    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.com/subscribe
    🐦Twitter - / rahulpnath
    📸Instagram - / rahulpnath
    🎥 Recording Setup and Workflow - www.rahulpnath.com/blog/youtu...
    Video Edited by my wife, Parvathy 😍
    Make sure to SUBSCRIBE to the channel. THANK YOU for helping me grow this channel !!
  • Jak na to + styl

Komentáře • 106

  • @ajaysonar1675
    @ajaysonar1675 Před 3 lety +15

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

  • @kailas141987
    @kailas141987 Před rokem

    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.

  • @payalsharma1413
    @payalsharma1413 Před 3 lety +6

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

    • @RahulNath
      @RahulNath  Před 3 lety

      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 Před 2 lety

      Same to same..

  • @bward4126
    @bward4126 Před 2 lety +1

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

    • @RahulNath
      @RahulNath  Před 2 lety

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

  • @88spaces
    @88spaces Před 2 lety

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

    • @RahulNath
      @RahulNath  Před 2 lety

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

  • @richardekeopara886
    @richardekeopara886 Před 3 lety

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

    • @RahulNath
      @RahulNath  Před 3 lety

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

  • @jhlee111
    @jhlee111 Před 2 lety +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  Před 2 lety

      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!

  • @ChosenHandle
    @ChosenHandle Před 3 lety +1

    Great video. Well structured and informative. Thank you!

    • @RahulNath
      @RahulNath  Před 3 lety +1

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

  • @vaelinalsorna1649
    @vaelinalsorna1649 Před 2 lety

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

    • @RahulNath
      @RahulNath  Před 2 lety +1

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

  • @soulfabuk
    @soulfabuk Před rokem

    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  Před rokem

      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. 😀

  • @albertszymanski7177
    @albertszymanski7177 Před 7 měsíci

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

    • @RahulNath
      @RahulNath  Před 7 měsíci +1

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

  • @mohammedmazin5405
    @mohammedmazin5405 Před 2 lety +1

    Super and clear explanatory helped me a lot. Thanks

  • @ashamarias
    @ashamarias Před 3 lety

    Great video Rahul. Well explained!

  • @DrGaurangGupta
    @DrGaurangGupta Před rokem

    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  Před rokem +1

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

  • @raagasongs
    @raagasongs Před 3 lety

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

    • @RahulNath
      @RahulNath  Před 3 lety

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

  • @iceneno2491
    @iceneno2491 Před 2 měsíci

    Excellent!

    • @RahulNath
      @RahulNath  Před 2 měsíci

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

  • @ransandu
    @ransandu Před 3 lety

    Thank you ! This helped a lot.

  • @velkumars26
    @velkumars26 Před 2 lety

    Nice explanation, much informative. Good work bro

  • @melk48111
    @melk48111 Před 3 lety +1

    awesome Rahul

    • @RahulNath
      @RahulNath  Před 3 lety

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

  • @UPSCCSE-ku7ej
    @UPSCCSE-ku7ej Před 3 lety +1

    Awesome man ...!!

  • @joshmachine777
    @joshmachine777 Před rokem

    Thanks!

    • @RahulNath
      @RahulNath  Před rokem

      Thank you Amit and for the super thanks !

  • @UPSCCSE-ku7ej
    @UPSCCSE-ku7ej Před 3 lety +1

    Excellent

  • @suryanarayanbaliarsingh5363

    Nice explanation..

    • @RahulNath
      @RahulNath  Před 3 lety

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

  • @GabrielGoncalves-ez1iv

    Thanks for this great explanation!!
    #aspnetoptionspattern

    • @RahulNath
      @RahulNath  Před rokem

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

  • @abdullahahmed8468
    @abdullahahmed8468 Před 3 lety

    amazing man

  • @tubeashu
    @tubeashu Před 3 lety +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  Před 3 lety +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.

  • @BarbarosYurttagul
    @BarbarosYurttagul Před rokem +1

    great

  • @LencoTB
    @LencoTB Před rokem

    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.

  • @SantoshSingh-nw8yy
    @SantoshSingh-nw8yy Před 2 lety

    Good one 👏

    • @RahulNath
      @RahulNath  Před 2 lety

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

    • @SantoshSingh-nw8yy
      @SantoshSingh-nw8yy Před 2 lety

      @@RahulNath yep subscribed immediately 🙂

    • @RahulNath
      @RahulNath  Před 2 lety

      @@SantoshSingh-nw8yy 🙏

  • @LencoTB
    @LencoTB Před rokem

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

  • @staker4
    @staker4 Před 3 lety

    👍

  • @klearner666
    @klearner666 Před 2 lety

    Can you Do this in Static class.?

  • @shreyasjejurkar1233
    @shreyasjejurkar1233 Před 3 lety +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  Před 3 lety

      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 Před 3 lety +1

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

    • @RahulNath
      @RahulNath  Před 3 lety +1

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

    • @shreyasjejurkar1233
      @shreyasjejurkar1233 Před 3 lety +1

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

  • @sarathbaiju6040
    @sarathbaiju6040 Před 2 lety +1

    Can you make a video series on SOLID principles?

    • @RahulNath
      @RahulNath  Před 2 lety +1

      Great suggestion! I will plan something.

  • @VindicatorMorty
    @VindicatorMorty Před 3 lety

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

    • @RahulNath
      @RahulNath  Před 3 lety

      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.

  • @melk48111
    @melk48111 Před 3 lety

    which editor are you using?

    • @RahulNath
      @RahulNath  Před 3 lety

      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/

  • @meayanaforever
    @meayanaforever Před 3 lety +1

    Second..❤️

  • @kalpeshblue2
    @kalpeshblue2 Před 3 lety +1

    first :)

  • @rohan4rich
    @rohan4rich Před 3 lety +1

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

    • @RahulNath
      @RahulNath  Před 3 lety

      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 Před 3 lety

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

    • @RahulNath
      @RahulNath  Před 3 lety

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

  • @piyalibasak6886
    @piyalibasak6886 Před rokem

    please explain a video of single tone scoped in distributed architecture

    • @RahulNath
      @RahulNath  Před rokem

      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 czcams.com/video/YR6HkvNBpX4/video.html
      What specific are you looking for with distributed architecture?

    • @piyalibasak6886
      @piyalibasak6886 Před rokem +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  Před rokem

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

  • @henrrypires794
    @henrrypires794 Před rokem

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

    • @RahulNath
      @RahulNath  Před rokem

      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 Před rokem +1

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

  • @expertreviews1112
    @expertreviews1112 Před 2 lety

    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  Před 2 lety

      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 Před 2 lety

      @@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  Před 2 lety

      @@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 Před 2 lety +1

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

    • @RahulNath
      @RahulNath  Před 2 lety

      @@expertreviews1112 Do let me know how that goes 👍