Liron Vinik’s Post

View profile for Liron Vinik, graphic

Software Developer | C# 🔡| .NET 💻 | Python 🐍 | RF 📻 | Building Secure Software Infrastructures to Protect People Every Day

🌟"𝗨𝗻𝗹𝗼𝗰𝗸𝗶𝗻𝗴 .𝗡𝗘𝗧 𝗦𝗲𝗰𝗿𝗲𝘁𝘀: 𝗧𝗵𝗲 𝗘𝗮𝘀𝘆 𝗚𝘂𝗶𝗱𝗲 𝘁𝗼 𝗔𝗱𝗱𝗧𝗿𝗮𝗻𝘀𝗶𝗲𝗻𝘁, 𝗔𝗱𝗱𝗦𝗶𝗻𝗴𝗹𝗲𝘁𝗼𝗻, 𝗮𝗻𝗱 𝗔𝗱𝗱𝗦𝗰𝗼𝗽𝗲𝗱”🌟 Hey LinkedIn Community! 🚀 While working on a project, I came across the following key concepts in the .NET world that I wanted to share: "AddTransient," "AddSingleton," and "AddScoped." As a new father, I recently introduced to the children's world. 🐣 Although my son is still very young, when I come across complicated terms or concepts, I simplify them and imagine how I will explain it to him in a few years. Let's start! 🔍 𝗛𝗶𝘀𝘁𝗼𝗿𝘆 & 𝗣𝘂𝗿𝗽𝗼𝘀𝗲: These terms come from the .NET framework, developed by Microsoft in the early 2000s. They are used to control how objects are created and managed in an application. In .NET, AddTransient, AddSingleton, and AddScoped configure DI services in Startup.cs (.NET Core 3.1) or Program.cs (.NET 5+). 🛠️ 𝟭. 𝗔𝗱𝗱𝗧𝗿𝗮𝗻𝘀𝗶𝗲𝗻𝘁: 𝗧𝗵𝗲 𝗢𝗻𝗲-𝗧𝗶𝗺𝗲 𝗨𝘀𝗲 𝗧𝗼𝗼𝗹 Imagine you have a coloring book. Each time you want to color a picture, you get a brand-new crayon. Once you're done, the crayon disappears. That's what AddTransient does. It creates a new object every time you ask for it. 🎯 𝗕𝗲𝘀𝘁 𝗨𝘀𝗲: ◽ When you need an object that is lightweight and not shared. ◽ Ideal for short-lived operations. 🏰 𝟮. 𝗔𝗱𝗱𝗦𝗶𝗻𝗴𝗹𝗲𝘁𝗼𝗻: 𝗧𝗵𝗲 𝗙𝗼𝗿𝗲𝘃𝗲𝗿 𝗙𝗿𝗶𝗲𝗻𝗱 Now, picture your favorite toy that you use every day. It's always the same toy, not a new one each time. That's AddSingleton. It creates an object once and then reuses it everywhere. It's like having a best friend who's always there for you. 🎯 𝗕𝗲𝘀𝘁 𝗨𝘀𝗲: ◽ For objects that contain global settings or shared resources. ◽ Great when you need consistency and a shared state across your app. 🔁 𝟯. 𝗔𝗱𝗱𝗦𝗰𝗼𝗽𝗲𝗱: 𝗧𝗵𝗲 𝗗𝗮𝘆-𝗟𝗼𝗻𝗴 𝗕𝘂𝗱𝗱𝘆 Think of AddScoped like a school friend. You meet them every day at school, but each day it's a new experience with the same person. Scoped objects are created once per request. They're there for you throughout a single journey, like a day at school, and then they're gone. 🎯 𝗕𝗲𝘀𝘁 𝗨𝘀𝗲: ◽ Perfect for objects that need to be the same within a single user request but different across different requests. ◽ Commonly used for request-related operations. 🌈 Conclusion: ◽ Use AddTransient for independent, short-lived objects. ◽ Choose AddSingleton for long-lived, shared objects. ◽ Opt for AddScoped for objects that live through a single user request. Understanding these concepts can help in designing efficient, effective .NET applications. They ensure that resources are used smartly, making your app faster and more reliable. Hope this simplified guide helps! Feel free to share your thoughts or experiences with these .NET services. keep learning! 👨💻📚 #dotnetcore #programmingconcepts #softwaredevelopment #learningisfun #softwareengineering #backend

  • No alternative text description for this image
Avner Mushnik, PhD

🌐 𝐅𝐮𝐥𝐥 𝐒𝐭𝐚𝐜𝐤 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐞𝐫 - Building End-to-End Web Platforms that Empower News Influencers and Media Companies to Craft Tailored Content | ⚛️𝑹𝒆𝒂𝒄𝒕 | 💻𝑵𝒐𝒅𝒆.𝒋𝒔 | 🍃𝑴𝒐𝒏𝒈𝒐𝑫𝑩 | ☁️𝑨𝑾𝑺 🚀✨

8mo

Very interesting article, and I also loved the comparison to the world of children! As a JS and React developer, I always find it fascinating to compare architectural solutions across different platforms. In React and Redux, we indeed focus a lot on state management and data flow, and it's intriguing to see how similar concepts are translated in NET.

Harel Wilner

NLP Developer and Prompt Engineer| Building NLP Models to Optimize Personal Branding | LLM| Pytorch | spaCy

8mo

In your opinion, what are some common pitfalls when using these dependency injection services, and how can they be avoided?

Evgeny Sinay

CEO @ Ultra AI | AI-Driven Marketer & Business Strategist | Data Research | OSINT | WEBINT | Competitive Intelligence | Practical AI Workshops

8mo

קודם כל שיהיה המון מזל טוב במסע האבהות שלך! מצפה לך דרך מהנה ומעניינת 😃 שנית, כתבת כאן תובנות ממש אדירות! נהניתי לקרוא! Liron Vinik

Oded Arlevski

HW Engineer || Music, electronics and bicycles lover | Maker | Hands-On Approach || 𝐓𝐫𝐲 ➤ 𝐅𝐚𝐢𝐥 ➤ 𝐑𝐞𝐩𝐞𝐚𝐭 ➤ 𝐒𝐮𝐜𝐜𝐞𝐞𝐝! 💪

8mo

Congrats for the newborn 👶🏼 He is lucky to have you as a father! Thanks for sharing these key concepts 💪🏼💪🏼

Ketty Vaisbrot

Backend Developer - Building Backend Infrastructures That Empower Mental Wellness Through Personalized Insights 💭 | Python 🐍 | Django 🚀 | AWS 🌻 | Docker 🐋

8mo

I really liked the abstraction of the concepts to a level that people who don't use the same technology could also understand 😎 Looking forward to reading your next posts 🤗

Ella Michalevich

Music - Driven English Learning 🎵

8mo

As always, i will start by saying that i loved the picture you generated! loved your method of simplifying complex things and imagine that you explain them to your child, i think it's a great way to also ensure your understanding about the matter. Thank you for explaining these concepts and their best use!

Lital Yehuda

Industrial and Management Engineer | Specializes in Information Systems | 🔎 QA Fan and Coffee Lover ☕️

8mo

I loved the analogy! It's a great way to simplify complex things. Thanks for sharing and congrats for the newborn 💐 ps amazing AI pic!

Adam Takrury

Backend Developer - Empowering Youths With Positive Actions Through Social Impact And Community Volunteering - Python | Django | AWS | Docker

8mo

🌟 Great breakdown of .NET services! Love the analogy with the coloring book and toys for AddTransient and AddSingleton. The school friend comparison for AddScoped makes it crystal clear. Awesome way to simplify complex concepts! 👏👨💻

Francis Ashkar

1nd year M.A Information Systems student specializing in IT | Aspiring data scientist| University of Bar ilan

8mo

Thanks for posting🙏

See more comments

To view or add a comment, sign in

Explore topics