Created
March 26, 2023 09:35
-
-
Save SirRufo/7233e84f6f39d2a0bb13442f10960f1a to your computer and use it in GitHub Desktop.
IServiceScopeFactory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FooService | |
{ | |
private readonly IServiceScopeFactory _scopeFactory; | |
public FooService( IServiceScopeFactory scopeFactory ) | |
{ | |
_scopeFactory = scopeFactory; | |
} | |
public void DoSomething() | |
{ | |
using IServiceScope scope = _scopeFactory.CreateScope(); | |
var barService = scope.Services.GetRequiredService<IBarService>(); | |
barService.DoWhateverWithTheService(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment