Back to Browse

Using IDbContextFactory and DbContext In The Same #AspNetCore app

10.5K views
Feb 23, 2023
10:36

Sometimes we need to work with both the regular DbContext and with IDbContextFactory at the same Asp.Net Core app. Here are two popular use cases: 1️⃣ Blazor Server, when we need to have both components and controllers and Razor Pages in the same project 2️⃣ When running background jobs, like Hangfire. ❗❗❗❗There's however a nasty exception just around the corner. If we try to run the application, we'll get an exception saying that a scoped service can't be consumed in a singleton service. 🤔So, what's wrong? Let me walk you through this. Join this channel to get source code access and other perks: https://www.youtube.com/channel/UCyTPru-1gZ7-4qblcKM0TiQ/join Also follow me here (especially if you are a self taught developer): ✅My other channel: https://www.youtube.com/@DanPatrascuTech ✅Facebook: https://www.facebook.com/danpatrascutech ✅Instagram: https://www.instagram.com/danpatrascutech/ ✅TikTok: https://www.tiktok.com/@danpatrascutech ✅Newsletter: https://www.danpatrascu.tech/ Contents 1. Intro: 00:00 2. Do we even need this? 01:02 3. Throwing Blazor Server in the mix 03:52 4. Annoying exception: 05:13 5. C'mon. it's that simple?! 07:32 6. Conclusion: 09:37 My setup: Camera - Canon EOS M50 Mark II: https://amzn.to/3SJxS4d Lav mic - Rode Lavalier GO Professional: https://amzn.to/3mmZS1B Condenser mic - Shure SM7B: https://amzn.to/3JaqjQN Audio console - Rodecaster PRO II: https://amzn.to/3KTVMIg Laptop - Dell Latitude: https://amzn.to/3KV4SEW Monitors - Benq 27 inch: https://amzn.to/3JbM6aU Lights - 2x Godox SL-60W: https://amzn.to/3KV3qCj

Download

0 formats

No download links available.

Using IDbContextFactory and DbContext In The Same #AspNetCore app | NatokHD